C++ (Qt) QButtonGroup *group = new QButtonGroup(this); connect(group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(onButtonClicked(QAbstractButton*))); group->addButton(pushButton_1); group->addButton(pushButton_2); group->addButton(pushButton_3); //.... group->addButton(pushButton_n);
C++ (Qt)void SomeClass::onButtonClicked(QAbstractButton *button){ QButtonGroup *group = qobject_cast<QButtonGroup*>(sender()); if (group) { Q_FOREACH(QAbstractButton *b, group->buttons()) { b->blockSignals(true); b->setChecked(b == button); b->blockSignals(false); } }}
C++ (Qt)while(!asleep()) sheep++;
QGridLayout *layout = new QGridLayout; layout->setSpacing(3); layout->setDefaultPositioning(3, Qt::Horizontal); QGroupBox *box = new QGroupBox(this); box->setFixedSize(200, 200); box->move(20, 20); box->setLayout(layout); QButtonGroup *grp = new QButtonGroup(box); grp->setExclusive(true); QPushButton *but[4]; for(int i=0; i<4; i++){ but[i] = new QPushButton(box); but[i]->setFixedSize(50, 30); but[i]->setText(QString::number(i+1)); but[i]->setCheckable(true); grp->addButton(but[i], i); layout->addWidget(but[i]); }