Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Solved QMenuBar in QWidget windows

    General and Desktop
    qmenubar qwidget
    3
    5
    406
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • artwaw
      artwaw last edited by

      Good afternoon.
      Quick question: is it possible to have QMenuBar on something else than QMainWindow?
      I tried to get the result but failed.
      I created the QWidget base empty window and added to the constructor:

          ui->setupUi(this);
          QMenuBar *menuBar = new QMenuBar(this);
          QMenu *browser = new QMenu(menuBar);
          QAction *closeAction = new QAction("Close",browser);
          browser->addAction(closeAction);
          menuBar->insertMenu(nullptr,browser);
      

      When I do show() and raise() this widget window it does get shown but without the menu bar... I am working on Qt 5.15.2.

      For more information please re-read.

      Kind Regards,
      Artur

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @artwaw last edited by

        @artwaw
        I believe so. Googling suggests you should be following this: http://redino.net/blog/2014/05/qt-qwidget-add-menu-bar/

        artwaw 1 Reply Last reply Reply Quote 2
        • JonB
          JonB @artwaw last edited by

          @artwaw
          I believe so. Googling suggests you should be following this: http://redino.net/blog/2014/05/qt-qwidget-add-menu-bar/

          artwaw 1 Reply Last reply Reply Quote 2
          • artwaw
            artwaw @JonB last edited by

            @JonB I don't know how this didn't pop up in my google search before I asked. It works, of course.

            The funny thing is that I considered using the layout (since I am prototyping now and finding out which solutions might be usable) - layouts would be used at the end anyway of course - but dropped the idea thinking "why bother for the prototype".

            Thank you!

            For more information please re-read.

            Kind Regards,
            Artur

            JoeCFD 1 Reply Last reply Reply Quote 1
            • JoeCFD
              JoeCFD @artwaw last edited by

              @artwaw keep a test case with ui file generated from designer. In this case, add menubar to mainwindow in designer. Then build your test case and check ui_*** file. You will be able to know how it is added.

              artwaw 1 Reply Last reply Reply Quote 1
              • artwaw
                artwaw @JoeCFD last edited by

                @JoeCFD Thank you, will investigate this avenue too!

                For more information please re-read.

                Kind Regards,
                Artur

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post