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 practical/standard way to share a QMenuBar for the whole application?

What's the practical/standard way to share a QMenuBar for the whole application?

Scheduled Pinned Locked Moved Solved General and Desktop
qmenubarcross platform
7 Posts 2 Posters 749 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.
  • W Offline
    W Offline
    w3bvkas9
    wrote on 4 Apr 2021, 10:08 last edited by
    #1

    Hi,

    Title. I want a single QMenuBar to be shared by all widgets/windows in my application, like a macOS menu bar (see What's the cross-platform way to create a QMenuBar?). In this menu bar, QActions should be enabled or disabled depending on the active window. What's the standard way to do this and where can I learn more about this? I fill a bit lost with this.

    Thanks a lot and let me know if I can help in any way.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 4 Apr 2021, 12:04 last edited by
      #2

      Hi,

      AFAIK, there's no standard way. But personally I would find it strange that the QMenuBar content changes when I switch from one widget to another.

      It's rather something I would expect from a QToolBar associated with the widget.

      Can you explain your use case ?

      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
      0
      • W Offline
        W Offline
        w3bvkas9
        wrote on 4 Apr 2021, 15:12 last edited by w3bvkas9 4 Apr 2021, 15:17
        #3

        Thanks. If you know of certain ways to do it, I would very much appreciate a link to an example or resources.

        I was not clear: the content of the menu bar does not change; QMenus and QActions are always the same. Rather, the fact that a given QAction is enabled or not changes with the windows.

        I do not like tool bars very much because they become very bloated when you have a lot of options. Also, menu bars make organizing stuff easy. My use case is the following: I have a main window and auxiliary windows (preferences widget, etc). Actions enabled for the main window should not be for the auxiliary windows.

        I want the menu bar to stay the same everywhere because I feel like having different menu bars makes it hard to remember where is each option (e.g. in the software Anki).

        EDIT: And how can you have a QMenuBar if you don't have any QMainWindow on screen?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 4 Apr 2021, 18:31 last edited by SGaist 4 Apr 2021, 18:31
          #4

          For the action state, you can use the enter/leaveEvent method for example.

          Depending on how these widgets are managed, you may also tie the action enabled state to the widget visibility.

          Which OS are you targeting ?

          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
          0
          • W Offline
            W Offline
            w3bvkas9
            wrote on 4 Apr 2021, 18:49 last edited by
            #5

            Ok, I will keep this in mind and so some research.

            We target Linux, macOS and Windows!

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 4 Apr 2021, 19:33 last edited by
              #6

              @w3bvkas9 said in What's the practical/standard way to share a QMenuBar for the whole application?:

              EDIT: And how can you have a QMenuBar if you don't have any QMainWindow on screen?

              QMenuBar is a widget that you can use with other widgets. QMainWindow has it integrated.

              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
              0
              • W Offline
                W Offline
                w3bvkas9
                wrote on 4 Apr 2021, 21:09 last edited by w3bvkas9 4 Apr 2021, 21:14
                #7

                Thanks. I think you answered the question, please feel free to add anything later if you want. I mark it as solved.

                1 Reply Last reply
                0

                3/7

                4 Apr 2021, 15:12

                • Login

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