[SOLVED] Prevent QMenu from being modal
-
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
-
QMEnu is a widget, so check out the widget class, there is something about isModel etc.
-
Thanks for trying to help, but isModal() and windowModal() both return 0
-
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?
-
(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 appearsbut 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
-
[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). -
So I guess I'm rolling my own menu. Thanks for your input.
-
and how do you plan to get the mouse events with your own custom menu widget?!
-
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.
-
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. -
yeah, just tried it and that doesn't work. the menu stops working.