Hiding Menu in MainWindow
-
-
@ModelTech
Can you show what you have tried? -
What kind of menu is it? A context menu? On a menu bar? On a toolbar's action? On a button?
If it's a menu added to a menu bar you should hide the action returned fromaddMenu()
, not the menu itself. -
It's the menu of the QMainWindow. This is how I created the QMenu with QMainWindow::menuBar()
AnalysisMenu = menuBar()->addMenu(tr("Analysis"));
Subsequently, I have some code that may or may not add QActions to this AnalysisMenu. For this I use QMenu::addAction. Finally, I have tried the following to hide the menu in case it does not have actions:
AnalysisMenu->setEnabled(!AnalysisMenu->actions().isEmpty());
-
setEnabled
does not hide an action. It only disables it (grays out depending on the style) and turns off a shortcut if it was assigned. UsesetVisible()
instead. -
If it doesn't work it means you're either not calling this code or you call it in a wrong place. It should be called whenever you change the contents of the menu (add/remove actions).
-
You'll gonna have to show some code - how you set up the menu, the part where you modify it and where you call the line.
setVisible(false)
hides an action so the problem is somewhere in your code.