PDA

View Full Version : radiobutton behavior on menubar



sp4rk3r
14th July 2008, 09:58
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.

luf
14th July 2008, 11:08
Quite simple actually.

Create actions you want on the menu, and add them in a QActionGroup.



QMenu *mymeny = new QMenu("mymenu");
QAction *item1 = new QAction("item1");
QAction *item2 = new QAction("item2");
QAction *item3 = new QAction("item3");
mymeny->addAction(item1);
mymeny->addAction(item2);
mymeny->addAction(item3);

QActionGroup myGroup = new QActionGroup();
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

sp4rk3r
15th July 2008, 04:37
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