frauzufall / ofxGuiExtended

ofParameter based GUI addon for openFrameworks; derived from the core OF ofxGui addon and ofxDOM.
MIT License
112 stars 29 forks source link

move only-one-active-toggle-feature from ofxGuiGroup to ofxToggle #16

Open frauzufall opened 9 years ago

frauzufall commented 9 years ago

as described in http://forum.openframeworks.cc/t/extending-ofxgui-with-new-widgets/16670/11?u=frauzufall

frauzufall commented 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!

martialgallorini commented 9 years ago

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

BenBergman commented 7 years ago

Was there every any progress on this? I could really use some sort of radio button or drop down in my current project.

frauzufall commented 7 years ago

Hey Ben, you can already use radio toggles! Just add the toggles to a group or panel and call group->setExclusiveToggles(true);

frauzufall commented 7 years ago

This issue is just about the way to implement that feature which I wanted to change once, I guess.