Contextual Menu in QML and Widget !
-
Hi all,
In my application, I have QQuickWidget which displays QML (obviously).
QML code is generated and my users can amend it.Some QML items required a contextual menu. So, I added Menu and MenuItem in the qml generator.
It works fine but I also need to display contextual menu to manage the view. This contextual menu is managed in QWidget side.
I tried to install an event filter on the root item or the QQuickWidget or QQuickWindow to be notify on Contextual Event.I can't reach the wanted behaviour.
Basically I want to display the QML contextual menu if the item under the mouse has one and when the qml has no contextual menu then displays the QWidget managed one.The only behaviour I got:
The QWidget contextual menu every where, even over the QML Item which has its own contextual menu.
If i disable all event filters I get my QML menu but of course no QWidget menu.Is there a way to do that ?
I don't want to traverse all QML item tree to find if there are items with Contextual menu.
Because, my generated code has item with contextual menu but my user may add contextual menu as wheel if they want.Thank you
Regards -
@Renaud-G. said in Contextual Menu in QML and Widget !:
If i disable all event filters I get my QML menu but of course no QWidget menu.
event filters are executed BEFORE delivering the event to the target object/widget.
How exactly are you showing the context menu in QML?
An approach could be (i dont't know if this works for sure) to subclass QQuickView, override mosuePressEvent / mouseReleaseEvent, call the base class implementation first and check if the mouse event was accepted. If not show the widget context menu.
-
@raven-worx Thanks, I will try that. I let you know if it works or not.