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. What's the cross-platform way to create a QMenuBar?

What's the cross-platform way to create a QMenuBar?

Scheduled Pinned Locked Moved Solved General and Desktop
qmenubar
6 Posts 2 Posters 2.1k 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.
  • D Offline
    D Offline
    detly
    wrote on last edited by
    #1

    In the documentation for QMainWindow::MenuBar it says:

    If you want all windows in a Mac application to share one menu bar, don't use this function to create it, because the menu bar created here will have this QMainWindow as its parent. Instead, you must create a menu bar that does not have a parent, which you can then share among all the Mac windows.

    But if I'm using Qt5 to write a cross platform application, I want my menu bar to appear properly on all desktop environments. On OS X I want the shared menu, on Linux, Windows and others I want the menubar in the main window.

    How can I achieve this?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you have that multiple window sharing the same QMenuBar use case ? If so just use an ifdef for OS X i and use the code shown in QMenuBar's documentation i.e.:

      #ifdef Q_OS_OSX
      QMenuBar *menuBar = new QMenuBar(nullptr);
      #endif
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Do you have that multiple window sharing the same QMenuBar use case ? If so just use an ifdef for OS X i and use the code shown in QMenuBar's documentation i.e.:

        #ifdef Q_OS_OSX
        QMenuBar *menuBar = new QMenuBar(nullptr);
        #endif
        
        D Offline
        D Offline
        detly
        wrote on last edited by
        #3

        @SGaist said:

        Do you have that multiple window sharing the same QMenuBar use case?

        No, in my case it's a single window. But it's still idiomatic to have the menubar at the top of the screen of OS X, even for a single-window app.

        Your #ifdef approach should work, cheers.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You may have misunderstood something then. That technique is to be used if you want to have all windows of your application use the same menu bar. However it won't change de position of the menu bar.

          Additionally, you shouldn't try to have that menu bar inside your main window because you'll be working against the OS X Human Interface Guidelines and you'll alienate your OS X users. Qt follows the platform recommendations for a good reason: the application should look native so that user of said platform will feel at home with your application.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply
          0
          • SGaistS SGaist

            You may have misunderstood something then. That technique is to be used if you want to have all windows of your application use the same menu bar. However it won't change de position of the menu bar.

            Additionally, you shouldn't try to have that menu bar inside your main window because you'll be working against the OS X Human Interface Guidelines and you'll alienate your OS X users. Qt follows the platform recommendations for a good reason: the application should look native so that user of said platform will feel at home with your application.

            D Offline
            D Offline
            detly
            wrote on last edited by
            #5

            @SGaist said:

            Additionally, you shouldn't try to have that menu bar inside your main window because you'll be working against the OS X Human Interface Guidelines and you'll alienate your OS X users. Qt follows the platform recommendations for a good reason: the application should look native so that user of said platform will feel at home with your application.

            Yes! This is what I want to achieve. But the docs imply that you need one line of code for OS X, and another for everything else. So... what's the correct way?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              If you mean that you want to follow the guidelines then you have nothing special to do, just use menuBar() and you're good to go.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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