开发者

Grouping one QRadioButton into several QButtonGroups

I have, for example, four QRadioButtons rb1, rb2, rb3, rb4. I set rb1 and rb3 checked:

rb1->setChecked(true);
rb3->setChecked(true);

Also, I have four QButtonGroups : bg12, bg34, bg13 and bg24, and make first two non-exclusive(they are by default):

bg13->setExclusive(false);
bg24->setExclusive(false);

The first case: I add rb1 and rb2 to the bg12, and rb3 and rb4 to the bg34. Then I add all the buttons to the grid layout, show the widget, and all that stuff, everything works as expected(two buttons are active, and button in one row excludes the other in its row).开发者_运维知识库

The second case: I add rb1 and rb2 to the bg12, and rb3 and rb4 to the bg34. Then I add rb1 and rb3 to the bg13, and rb2 and rb4 to the bg24. Now it does not work as I expected, they all behave like «free» buttons, and I can check/uncheck any of them. So, what am I doing wrong?

Upd: I've also tried it with QPushButtons(so, no exclusivity and such stuff), and it just looks like if button is already in a QButtonGroup, and I add it do another one, it doesn't belong to the first anymore :(

I guess, you might wonder why would I do this wierd stuff - I'll explain. I want to keep a vector of pairs of QRadioButtons, and a button in each pair must exclude the another in its pair(they represent two exclusive states), so I want to group buttons in each pair in an exclusive QButtonGroup(like bg12and bg34 in the example) and also add, for example, all the first buttons of each pair to another QButtonGroup(non-exclusive, like bg13 from the example) and give it an id. So, I would be able to handle state changes with one of the signals QButtonGroup class provides us and the id. Maybe there's a simplier way?


The QAbstractButton holds one QButtonGroup as member, so a button can only belong to one group.

But for the non-exclusive group, you can use QSignalMappers instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜