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. [SOLVED] Prevent QMenu from being modal

[SOLVED] Prevent QMenu from being modal

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 4.4k 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.
  • L Offline
    L Offline
    lisabeeren
    wrote on 21 Nov 2013, 12:37 last edited by
    #1

    Hi

    My application has a toolbar which shows QMenu's when the user clicks on items.

    The issue I'm having is that QMenu's appear to be modal. While the menu is visible, no mouse move events are generated in the underlying window, the "raising" of the appearance of buttons when the mouse hovers over doesn't work, etc.

    Is there a way to keep the underlying window responsive when a QMenu is visible?

    with thanks

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jeroentjehome
      wrote on 21 Nov 2013, 13:37 last edited by
      #2

      QMEnu is a widget, so check out the widget class, there is something about isModel etc.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lisabeeren
        wrote on 21 Nov 2013, 13:40 last edited by
        #3

        Thanks for trying to help, but isModal() and windowModal() both return 0

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 21 Nov 2013, 14:10 last edited by
          #4

          QMenu widgets are never modal ... what would be the sense of?!
          Instead they are top level widgets which are activated once they are opened. Thus your other top-level windows do not receive mouse events (Only active windows do).
          For windows you can read "this":http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).aspx for more details.

          The only thing to prevent this is setting the window flags of the menu to become a child widget in the same window. But this is not how QMenu should behave.

          Why do you need this in the first place?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lisabeeren
            wrote on 21 Nov 2013, 14:24 last edited by
            #5

            (sorry, QMenu items are modal in the sense that they block mouse events to the parent window, i appreciate that this may not satisfy all that the definition of modal entails, and apologise for the confusion)

            thanks for the link raven, obviously i'm trying to solve the problem in Qt/platform independent way, but sure, i may need to do some platform specific hacks; or maybe roll my own menu widget.

            The problem I'm trying to solve is:

            a) user moves mouse over toolbar button
            b) button highlights with hover
            c) user clicks button
            d) menu appears

            but user does not want anything in that menu

            e) user hovers mouse over another toolbar button (without dismissing the old menu)
            f) that button does not highlight with the hover (additionally, the old button remains hover-highlighted, because it doesn't receive the mouseout event. even if you dismiss the menu, this hover-highlight remains until you move the mouse back over it again)

            i want for the underlying window to continue to handle mouse events while the menu is visible; otherwise the application looks broken.

            thanks

            1 Reply Last reply
            0
            • R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 21 Nov 2013, 14:55 last edited by
              #6

              [quote author="lisabeeren" date="1385043842"]
              thanks for the link raven, obviously i'm trying to solve the problem in Qt/platform independent way, but sure, i may need to do some platform specific hacks; or maybe roll my own menu widget.
              [/quote]
              the link should have showed you that it isn't possible. Since Qt also just receives the messages from the operating system and converts them to QEvents there wont even be a Qt way. Non active windows won't receive mouse events (at least in MS WIndows).

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lisabeeren
                wrote on 21 Nov 2013, 14:57 last edited by
                #7

                So I guess I'm rolling my own menu. Thanks for your input.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  raven-worx
                  Moderators
                  wrote on 21 Nov 2013, 14:59 last edited by
                  #8

                  and how do you plan to get the mouse events with your own custom menu widget?!

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lisabeeren
                    wrote on 21 Nov 2013, 15:02 last edited by
                    #9

                    i'll just make a QWidget which looks like a menu, and is /absolutely/ positioned on top of all the widgets of the window. This way it will still be a part of the same window, and will not prevent mouse events.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      raven-worx
                      Moderators
                      wrote on 21 Nov 2013, 15:09 last edited by
                      #10

                      ok that would work. You would have to set the window as the parent widget of your menu and ensure that it is raised all the time.
                      The only drawback is that it can not overlap the window's frame (it will be cut at the window boundaries).

                      Maybe you can use QMenu for this and don't need to create a custom implementation.
                      QMenu::setWindowFlags(Qt::Widget);
                      Maybe this already is enough.

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        lisabeeren
                        wrote on 21 Nov 2013, 15:14 last edited by
                        #11

                        yeah, just tried it and that doesn't work. the menu stops working.

                        1 Reply Last reply
                        0

                        2/11

                        21 Nov 2013, 13:37

                        9 unread
                        • Login

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