在Qt中,直接使用QMenu::hide()是不會隱藏這個菜單的,想要隱藏菜單,因為每個菜單都是與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);