Not possible to hide a QMenu object QMenu::setVisible()?

7.1k views Asked by At

I have built up a QMenu MainMenu on top of my MainWindow in my application. As everybody is used to it, I have following QMenu Main menus:

File - Edit - SuperHeavyExpertMenus - Settings - Help

I would like to hide the sub tree SuperHeaverExpertMenus initially, on program start, because it conatins a lot of settings, which might confuse beginner users.

I want to show that sub tree with SuperHeavyExpertMenu, when a checkbox in Settings is true, for instance.

I can hide the children QActions of the QMenu s above, vie QAction:setVisible(false) . but I can do that for the QMenu ?

Is there a way to hide the QMenu ?

3

There are 3 answers

1
Angie Quijano On

If I understood correctly your problem, the way you can solve it is whit something like this:

ui->menuYouWantToHide->menuAction()->setVisible(false);

I hope to be useful.

2
Tomse On

Qmenu doesn't have setVisible(), or hide(), but you can change the title instead:

ui->MenuYouWantToHide->setTitle("");

This will remove the title, and therefore the "Action" that make up the button in your GUI.

0
Swift - Friday Pie On

Visibility and enable-ity of QAction-based widgets can be controlled via QAction object connected with them.

Qt documentation, even latest versions omit multiple accessor functions from list of public ones. Instead they are referenced under relevant getters, e.g. QAction::setVisible is listed under QAction::isVisible topic.