在Qt中,调用QMenu::hide()或QMenu::setVisible(false)是不会隐藏这个菜单的,想要隐藏菜单,需要将与菜单关联起来的动作隐藏。
因为每个菜单都是与QAction联系起来的,因此使用QMenu::menuAction()->setVisible(false),就可以把这个菜单隐藏。
The menu is represented in the menu bar using a QAction. In order to
hide the menu “menuTest1” you have to hide its associated action. You
can access that action using QMenu::menuAction(), like this:
menuTest1->menuAction()->setVisible(false);