Reputation: 2418
I'm working on a gui project in Qt Creator
How would I make a group of 40 push buttons set to checkable, but only one can be checked at a time? I looked into it a bit and QButtonGroup seemed interesting, but I just don't understand. :(
I have already laid out the 40 push buttons and set each one to checkable.
Thanks for your time :)
Upvotes: 2
Views: 3242
Reputation: 40512
I hope that you're adding 40 buttons programmatically, not manually in Qt Designer, so you should be able to create a list of all buttons: QList<QPushButton*> my_buttons
. You need to create a button group and put all buttons into it. It's quite simple:
QButtonGroup* group = new QButtonGroup(this);
foreach(QPushButton* button, my_buttons) {
group->addButton(button);
}
Upvotes: 1