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.
  • A Offline
    A Offline
    artwaw
    wrote on 1 Oct 2021, 14:12 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

    J 1 Reply Last reply 1 Oct 2021, 14:57
    0
    • A artwaw
      1 Oct 2021, 14:12

      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.

      J Offline
      J Offline
      JonB
      wrote on 1 Oct 2021, 14:57 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/

      A 1 Reply Last reply 1 Oct 2021, 15:22
      2
      • J JonB
        1 Oct 2021, 14:57

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

        A Offline
        A Offline
        artwaw
        wrote on 1 Oct 2021, 15:22 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

        J 1 Reply Last reply 1 Oct 2021, 19:09
        1
        • A artwaw
          1 Oct 2021, 15:22

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

          J Offline
          J Offline
          JoeCFD
          wrote on 1 Oct 2021, 19:09 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.

          A 1 Reply Last reply 4 Oct 2021, 08:25
          1
          • J JoeCFD
            1 Oct 2021, 19:09

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

            A Offline
            A Offline
            artwaw
            wrote on 4 Oct 2021, 08:25 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

            5/5

            4 Oct 2021, 08:25

            • Login

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