Exclusive Push Button
-
I want to toggle between several push buttons such that only one of them can be enabled at any given time - essentially, a set of Radio buttons that appear more like Push buttons. Also, they're located in completely different Group Boxes (although within the same dialog of course).
I'm slightly tempted to use n*n enable/disable signal-slots, but that does sound both ridiculous and onerous. Is there a different way to implement this? If so, can I also pull it off with Qt Designer?
Thanks.
-
Hi,
Use QPushButton's "autoexclusive":http://qt-project.org/doc/qt-5.0/qtwidgets/qabstractbutton.html#autoExclusive-prop property.
-
you can do the same like you would do with QRadioButtons, since "QButtonGroup":http://qt-project.org/doc/qt-4.8/qbuttongroup.html is based on QAbstractButtons.
-
I tried using the QPushButton "autoexclusive":http://qt-project.org/doc/qt-5.0/qtwidgets/qabstractbutton.html#autoExclusive-prop property, which worked wonderfully for the buttons within the same parent. This does not appear to apply to the buttons beyond the immediate parent, which is what I am trying to do.
-
Hi,
Did you use raven-worx suggestion ? QButtonGroup sounds like what you need.
-
Hi,
bq. I’m slightly tempted to use n*n enable/disable signal-slots, but that does sound both ridiculous and onerous. Is there a different way to implement this? If so, can I also pull it off with Qt Designer?
think simpler :)
put your push buttons in a list, do just one slot, connect clicked signal of each to the only slot and use
@QPushButton *button = (QPushButton *)sender();@
may be focusWidget could be used in some context too, and uncheck all buttons in the list less the sender
hope this helps :)
Cheers!
-
[quote author="NicuPopescu" date="1381224884"]
think simpler :)put your push buttons in a list, do just one slot, connect clicked signal of each to the only slot and use[/quote]
and this should really be simpler than using a simple QButtonGroup?!
I would recommend this approach since is more error prone either... -
since I quoted him I meant is simpler than his thinking, not others :)
bq. I would recommend this approach since is more error prone either…
which one is more error prone?
myself I found none of them as being error prone once everything is done right ... I reckon though what I suggested is more cumbersome :)
Cheers!