How to disable and enable the menus in menu bar?



  • @nathan:
    how to disable and enable the menus in menu bar..
    thanks for your good response..?

    [andreyc EDIT: I moved this question from old thread (2011)]



  • imyournathan if you have a question please start new thread next time.



  • @
    QMenuBar *menuBar;
    QMenu *menuFile;
    QAction *actionOpen;
    QAction *actionClose;

    menuBar = new QMenuBar(MainWindow);

    menuFile = new QMenu(menuBar);
    menuFile->setTitle("File");

    actionOpen = new QAction(MainWindow);
    actionOpen->setText("Open");

    actionClose = new QAction(MainWindow);
    actionClose->setText("Close");

    menuBar->addAction(menuFile->menuAction());
    menuFile->addAction(actionOpen);
    menuFile->addAction(actionClose);
    @

    To disable one of the items or whole "File" menu
    @
    actionOpen->setEnable(false);
    menuFile->setEnable(false);
    @

    To enable them back
    @
    actionOpen->setEnable(true);
    menuFile->setEnable(true);
    @



  • @andreyc

    Approaching like this would disables the QMenu, and it's children are no longer visible. Is there is a way in which the user can see that ta QMenu is disable but still can see it's children?

    menuFile->setEnable(false);
    


  • @sami1592

    In the same way, You can disable all the sub menus and enable the main menu.


Log in to reply
 

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