Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMenuBar in QWidget windows

QMenuBar in QWidget windows

Scheduled Pinned Locked Moved Solved General and Desktop
qmenubarqwidget
5 Posts 3 Posters 1.2k Views
  • 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.
  • artwawA Offline
    artwawA Offline
    artwaw
    wrote on last edited by
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • artwawA artwaw

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

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

      artwawA 1 Reply Last reply
      2
      • JonBJ JonB

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

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        @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

        JoeCFDJ 1 Reply Last reply
        1
        • artwawA artwaw

          @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!

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          @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.

          artwawA 1 Reply Last reply
          1
          • JoeCFDJ JoeCFD

            @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.

            artwawA Offline
            artwawA Offline
            artwaw
            wrote on last edited by
            #5

            @JoeCFD Thank you, will investigate this avenue too!

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved