Show/hide top-level submenu at runtime



  • In my application, I want to dynamically show or hide top-level submenus at runtime. To do so, we use QWidget::setVisible() as QMenu is derived from QWidget after all. Unfortunately, it does not work. Our code looks like this:
    In mainwindow.h:
    @
    QMenu *helpMenu;
    QAction *actionHelpAbout;
    @

    In mainwindow.cpp:
    @
    actionHelpAbout = new QAction(tr("&About"), this);
    helpMenu = menuBar()->addMenu(tr("&Help"));
    helpMenu->addAction(actionHelpAbout);
    helpMenu->setVisible(false);
    @

    [EDIT: code formatting, please wrap in @-tags, Volker]



  • the only way I see is to disable the menu item/action or remove it from the menu or menu bar.



  • [quote author="Volker" date="1329084878"]the only way I see is to disable the menu item/action or remove it from the menu or menu bar.[/quote]
    Thanks, I'll try your method today.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.