QMenu . QAction how can I add "checked "?
-
This post is deleted!
-
@AnneRanch
A menu can't be made checkable, but an action can.
This alters your code to make the first action you add checkable.subMenu[ index_main] = m_ui->menuWindow_cpntrol->addMenu("DEBUG " + list[ index_main] + " #" + QString::number( index_main)); QAction *checkableAction = subMenu[index_main]->addAction("Test checkable action"); checkableAction->setCheckable(true); // makes it checkable, unchecked by default. checkableAction->setChecked(true); // makes it checked //subMenu[ index_main]->checkable(true); subMenu[ index_main]->setVisible(true); //subMenu[ index_main]->setCheckable(true);
-
-
This post is deleted!
-
@AnneRanch
I used the provided code.
It shows the mechanism of making an action checkable and changing the checked property.
That works with any action, no matter where in the menu tree it is located.
You can use it in the main menu just as well.
Or you can post the code that creates the main menu. -
This post is deleted!
-
@AnneRanch
Could you post all the code responsible for creating menus and submenus? I am getting lost, because I don’t see the big picture. Could you also sketch the desired menu structure, including checkboxes on actions? -
FINALLY...
here a current WORKING as expected - both menu and submenu have check boxes and only main menu has "arrows"....
Unless there are objections I am going to clean up the worthless code...
Thanks foe sticking with the problem...
mainAction[index_main] = m_ui->menuWindow_cpntrol->addAction(list[ index_main] + " #" + QString::number( index_main)); mainAction[index_main]->setCheckable(true); //adds arrows mainAction[index_main]->setMenu(tempmenu); subAction[index_main] = tempmenu->addAction(list_hcitool[ index_main] + " #" + QString::number( index_main)); subAction[index_main]->setCheckable(true);