m_btn_5->setChecked(false); m_btn_6->setChecked(false); m_btn_7->setChecked(false); qDebug()<<btn_name; }elseif(btn_name.compare("btn5") ==0) { m_btn_1->setChecked(false); m_btn_2->setChecked(false); m_btn_3->setChecked(false); m_btn_4->setChecked(false); m_btn...
// 设置互斥 m_pButtonGroup->setExclusive(true); for (int i = 0; i < 3; ++i) { QRadioButton *pButton = new QRadioButton(this); // 设置文本 pButton->setText(QString::fromLocal8Bit("切换%1").arg(i + 1)); pLayout->addWidget(pButton); m_pButtonGroup->addButton(pButton); ...
1.还是先设置所要互斥的按钮的属性 2.需要用到Qt的QButtonGroup类,实例化一个QButtonGroup对象,然后将所有需要互斥的按钮全部添加进去 1QButtonGroup * box =newQButtonGroup;2//设置是否互斥3box->setExclusive(true);4//将需要互斥的按钮全部添加到 QButtonGroup 中5box->addButton(ui.pushButton);6box->...
QList<QAbstractButton *> buttons() const:返回按钮组中的所有按钮。 void setExclusive(bool exclusive):设置按钮组是否为互斥模式。如果 exclusive 为 true,则在组中只有一个按钮可以被选中;如果为 false,则允许多个按钮同时被选中。 void setId(QAbstractButton *button, int id):为按钮 button 设置一个整数 ID。
setAutoExclusive(bool exclusive): 设置单选按钮是否自动排除其他已选中的单选按钮。 QAbstractButton 中和 QRadioButton 关系较大的属性 三、QRadioButton的使用(代码示例) 1. 使用代码编写选择性别 在界⾯上创建⼀个 label, 和 3 个 单选按钮RadioButton ...
actionGroup->setExclusive(true); QMenu::item:exclusive { background:blue; } QMenu::item:exclusive:selected { background:red; } 14、:first,QTabBar的第一个标签。 15、:flat,按钮扁平状态(非按下时不绘制按钮背景)。例: QPushButton:flat{ ...
QButtonGroup->setExclusive(true);实现非独占效果,可以多选。 信号:stateChanged(int state);参数为int类型,其中Qt::checked表示“选中”;Qt::Unchecked表示“未选中”; Qt::PartiallyChecked表示“半选中”。 可以连接自定义的槽函数: connect(ui.checkBox, SIGNAL(stateChanged(int)), this, SLOT(onStateChanged...
QButtonGroup(QObject * parent = 0) ~QButtonGroup() bool exclusive() const void setExclusive(bool) //设置button是否互斥,默认互斥 void addButton(QAbstractButton * button, int id = -1) QAbstractButton * button(int id) const QList<QAbstractButton *> buttons() const QAbstractButton * checkedButto...
菜单中的独立项使用::item子组件定制,除了常见的伪状态,::item还支持:selected, :default, :exclusive以及:non-exclusive等伪状态。利用这些伪状态,可以为不同状态的菜单项定制出不同的外观。对于可勾选的菜单项,使用::indicator对勾选标记进行定制,::separator则定制菜单项之间的分隔符;对于有子菜单的菜单项,其箭...
group->setExclusive(false); group->setEnabled(false); #五、处理动作的选择状态改变 QActionGroup提供了一个信号`triggered(QAction *action)`,该信号在动作的选择状态发生改变时被触发。我们可以通过该信号与槽机制来处理动作的选择状态改变事件。以下是一个处理动作选择状态改变的简单示例: ...