Open frauzufall opened 9 years ago
@martialgallorini I am looking into the setExclusive feature of toggles in QT - I only find this: http://doc.qt.io/qt-4.8/qbuttongroup.html There the attribute is also applied to the group. Am I missing something or do you have another reference for me? Thank you!
Hello @frauzufall ,
You can make all buttons checkable (to set them active or not) and make them auto exclusives. On a layout if you set all buttons auto exclusive, there will be only one button active at the same time for all buttons. If you need multiple groups of auto exclusive buttons, you can put them in a button group. More generally you can put them in different widgets (not only button groups) as the auto exclusive property action is relative to the parent widget. Say if you have 8 buttons and 4 in 2 different groups, all auto exclusive, you can have 2 buttons checked at the same time, eg. one in each group.
Example code :
// create a group
QButtonGroup* group = new QButtonGroup(this);
// create buttons
button1 = new QPushButton("Button 1", this);
button2 = new QPushButton("Button 2", this);
button3 = new QPushButton("Button 3", this);
// add buttons to group
group->addButton(button1);
group->addButton(button2);
group->addButton(button3);
// set buttons checkable and mutually exclusive
button1->setCheckable(true);
button1->setAutoExclusive(true);
button2->setCheckable(true);
button2->setAutoExclusive(true);
button3->setCheckable(true);
button3->setAutoExclusive(true);
Groups are from QButtonGroup class : http://doc.qt.io/qt-5/qbuttongroup.html
Buttons are QPushButton class objects, and some of the button properties, like "exclusive", are held by the base QAbstractButton class : http://doc.qt.io/qt-5/qabstractbutton.html
hope this helps
Was there every any progress on this? I could really use some sort of radio button or drop down in my current project.
Hey Ben, you can already use radio toggles! Just add the toggles to a group or panel and call group->setExclusiveToggles(true);
This issue is just about the way to implement that feature which I wanted to change once, I guess.
as described in http://forum.openframeworks.cc/t/extending-ofxgui-with-new-widgets/16670/11?u=frauzufall