質問

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);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top