Main menu set with submenu - triggering issue
-
I have QMenu with sub QMenu
I can trigger on submenu OK.
I wanted to be able to trigger on maim menu to run all the submenu options.
I can attempt to set the check box - trigger - and it reacts ( turns grey ) but no connect is generated and no "check mark " either.My question is - can that be even done in Qt?
// build main menu TOK subMenu[index] = m_ui->menuWindow_cpntrol; subMenu[index] = subMenu[index] ->addMenu(list[index] + " # " + QString::number(index)); subAction[index] = subMenu[index]->addMenu(subMenu[index]); subAction[index]->setVisible(true); subAction[index]->setCheckable(true); // TOK subAction[index]->setText("DEBUG test main menu "); // connect to main submenu connect(subMenu[index] , &QMenu::triggered, this , [=]() { this->processAction(index,index) ;});
-
@AnneRanch
This has been answered at length in this post. The summary is: It's better to keep track of yourQAction
objects and connect to theirtriggered
signal.
The connect statement is syntactically correct. It will call the lambda each time an action ofsubMenu[index]
is triggered. The information, which action (i.e. which line of the menu) was selected, is lost. The code is unlikely to produce a meaningful result.I think that you mix up actions and menus. That has lead to an architectural problem. It can be fixed by code refactoring,
-
@AnneRanch said in Main menu set with submenu - triggering issue:
My question is - can that be even done in Qt?
No.
A menu either opens a submenu or it triggers an action on click.
-
@TomZ Then I will have a submenu which will run all the tasks. Easy , and remove the check box on the main menu because it cannot work...Thanks
-
@AnneRanch
You may have been trying to do what I did some time ago, but discovered it does not work so is not allowed in Qt. If you have a sub-menu on a menu --- i.e. the menu has that > you click on to "slide out" the sub-menu --- then although Qt allows you also put a checkbox on the parent menu item which has the > slide-out it actually does not work correctly for checking the box, and cannot be made to do so. Do not try to put a checkbox on a menu item which has a child menu slide-out.
1/5