Nominate our 2022 Qt Champions!

How to return deleted main menu bar?

  • I deleted the main menu bar out of my project, how do I return it?

    For the documentation:
    @QMenuBar * QMainWindow::menuBar() const @
    Returns the menu bar for the main window.

    However, I don't quite understand how to use it?

  • I don't quite inderstand what you want it to do. From the QMainWindow::menuBar() doc entry:

    bq. Returns the menu bar for the main window. This function creates and returns an empty menu bar if the menu bar does not exist.

    This means that calling this function when you have no menuBar will yield you a new, empty one - you just need to specify your intentions regarding its use.

  • Why do you use a QMainWindow at all? Maybe a QDialog would be better then.

    Anyway, I think you can remove the menubar like this:
    @QList<QMenuBar*> widgets = this->findChildren<QMenuBar*>();

    QMenuBar *current = NULL;

    foreach(current, widgets)
    delete current;


    EDIT: Sorry, I misunderstood. Though OP is looking to remove the menubar.

  • I want the menu bar back on my form. How do I accomplish this?

  • Please clarify! You mean programmatically or in the Qt Designer?

    I think you already found the answer for the former case. And in the later case:
    Rightclick → Create Menu Bar ;-)

Log in to reply