简体   繁体   中英

(Qt C++) QButtonGroup with Checkable PushButtons?

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 :)

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM