QT 按键组 - QButtonGroup

链接: https://blog.csdn.net/potato123232/article/details/118788209?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167003540616800215050615%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=167003540616800215050615&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allbaidu_landing_v2~default-3-118788209-null-null.142v67control,201v3control_1,213v2t3_control2&utm_term=QButtonGroup&spm=1018.2226.3001.4187

示例:创建一个按键组,并将其设置为互斥选择,该按键组中放入4个按键,设置初选中按钮为id==1,并设置了相应的信号与槽。

buttonGroup = new QButtonGroup();
buttonGroup->setExclusive(true);// 如果此属性为真,则在任何给定时间只能选中组中的一个按钮。
buttonGroup->addButton(ui->SB1, 0);
buttonGroup->addButton(ui->SB2, 1);
buttonGroup->addButton(ui->SB4, 3);
buttonGroup->addButton(ui->SB5, 4);
// 该槽函数做了一件事:修改被选中按键的样式
connect(buttonGroup, SIGNAL(buttonToggled(int,bool)), this, SLOT(Button(ButtonsBarToggled(int,bool)));
buttonGroup->button(1)->setChecked(true);  // 为customGroup组设置初选项

你可能感兴趣的:(笔记,qt,qbuttongroup)