radiobutton behavior on menubar
I'd like to have a menubar with items that are checkable and mutually exclusive of one another. That is I want a series of checkboxes to behave like a radio button group under a menuitem on the menubar. How does one go about that? I've managed to get myself into an infinite loop of signalling when trying to link a toggled( bool ) signal to the toggle() slot of another action and vice versa.
Re: radiobutton behavior on menubar
Quite simple actually.
Create actions you want on the menu, and add them in a QActionGroup.
Code:
mymeny->addAction(item1);
mymeny->addAction(item2);
mymeny->addAction(item3);
myGroup->addAction(item1);
myGroup->addAction(item2);
myGroup->addAction(item3);
connect(item1, SIGNAL(triggered()), someobject, (SLOT(item1slot()));
connect(item2, SIGNAL(triggered()), someobject, (SLOT(item2slot()));
connect(item3, SIGNAL(triggered()), someobject, (SLOT(item3slot()));
Remember to add either the actions to a menubar directly, or add the menu to a menubar, depending on the layout you want.
cheers,
Leif
Re: radiobutton behavior on menubar
Luf,
Thank you. I was looking high and low for that. I'm a firm believer in RTFM... and I've got quite a few books regarding QT4, but couldn't find that example anywhere. Google is dead to me. :)
My next question is whether or not this approach is easily attainable inside Designer? I don't care if it is, but was curious if the relationship can be established at the layout stage.
-steve