Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to do radio buttons in Qt 4.4.3 menus

Tags:

On Linux would like to have a set of menu items which are mutually exclusive and have the currently selected one be designated by a radio button instead of a checkbox.

Is there a way to do this in Qt v4.4.3 easily?

like image 799
WilliamKF Avatar asked Dec 17 '09 00:12

WilliamKF


People also ask

Which menu is used to create a radio button?

To put a radio button in a menu, use the JRadioButtonMenuItem class.

What is the shortcut key of radio button?

When focus moves to the group in which a radio button is selected, pressing Tab and Shift+Tab keys move focus to the radio button that is checked. Up Arrow and Down Arrow keys move focus and selection. Up Arrow key press moves focus and selection forward through the radio buttons in the group.


1 Answers

I believe you would want to use QtActionGroup to group those menu items which should be mutually exclusive. It also makes them look like a radio button when rendered. Smth like this:

QActionGroup* group = new QActionGroup( this );  ui->actionTest1->setCheckable(true); ui->actionTest2->setCheckable(true); ui->actionTest3->setCheckable(true);  ui->actionTest1->setActionGroup(group); ui->actionTest2->setActionGroup(group); ui->actionTest3->setActionGroup(group); 

3 menu items above should be groped together; more details here : QActionGroup Class Reference

like image 80
serge_gubenko Avatar answered Sep 22 '22 02:09

serge_gubenko