Custom events in QML
-
We have some alternate input devices in our system. Right now we are propagating those events via signals to underlying Items in QML. This is cumbersome and messy.
I have started looking at the QEvent and how it works with QQuickItem. It looks like MouseArea is based upon QQuickItem and seems to capture mouse events. I have found that there is a event handler for QInputEvents already in QQuickItem. I would just base my Item similar to MouseArea. Then filter and capture my custom events based upon QInputEvent.
What I am not understanding is how QML prioritizes those events to which Item. I don't understand how QML would know which Item should get the event first. MouseArea doesn't use the event function inputMethodEvent. There is no position associated with our devices. So I am not sure how to rectify which Item should get what events.
-
I've had success interfacing a custom input device without an implicit position as a keyboard. Determining which Item received input used the well established focus mechanism. This had the added benefit of enabling cheap and readily available testing hardware.
-
We have some alternate input devices in our system. Right now we are propagating those events via signals to underlying Items in QML. This is cumbersome and messy.
I have started looking at the QEvent and how it works with QQuickItem. It looks like MouseArea is based upon QQuickItem and seems to capture mouse events. I have found that there is a event handler for QInputEvents already in QQuickItem. I would just base my Item similar to MouseArea. Then filter and capture my custom events based upon QInputEvent.
What I am not understanding is how QML prioritizes those events to which Item. I don't understand how QML would know which Item should get the event first. MouseArea doesn't use the event function inputMethodEvent. There is no position associated with our devices. So I am not sure how to rectify which Item should get what events.
It looks like it prioritizes by last created Item. At least for eventFilter it does. I have used properties such as "enabled" and "composePropagatedEvents" to control scoping a bit from the QML side. I also made it so that my signal handlers in QML (connections made by using on<Signal> methods) are detected and used if they exist. If not they are ignored. I even implemented the "accepted" feedback as well for determining propagation. I modeled it a lot off of the MouseArea object for inspiration.
-
F fcarney has marked this topic as solved on
-
It looks like it prioritizes by last created Item. At least for eventFilter it does. I have used properties such as "enabled" and "composePropagatedEvents" to control scoping a bit from the QML side. I also made it so that my signal handlers in QML (connections made by using on<Signal> methods) are detected and used if they exist. If not they are ignored. I even implemented the "accepted" feedback as well for determining propagation. I modeled it a lot off of the MouseArea object for inspiration.
@fcarney said in Custom events in QML:
It looks like it prioritizes by last created Item. At least for eventFilter it does. I have used properties such as "enabled" and "composePropagatedEvents" to control scoping a bit from the QML side. I also made it so that my signal handlers in QML (connections made by using on<Signal> methods) are detected and used if they exist. If not they are ignored. I even implemented the "accepted" feedback as well for determining propagation. I modeled it a lot off of the MouseArea object for inspiration.
I don't understand what
It
is,and whether the strategy is successful.Is composePropagatedEvents supposed to be MouseArea.propagateComposedEvents?
-
@fcarney said in Custom events in QML:
It looks like it prioritizes by last created Item. At least for eventFilter it does. I have used properties such as "enabled" and "composePropagatedEvents" to control scoping a bit from the QML side. I also made it so that my signal handlers in QML (connections made by using on<Signal> methods) are detected and used if they exist. If not they are ignored. I even implemented the "accepted" feedback as well for determining propagation. I modeled it a lot off of the MouseArea object for inspiration.
I don't understand what
It
is,and whether the strategy is successful.Is composePropagatedEvents supposed to be MouseArea.propagateComposedEvents?
-
Thanks for the clarification.
@fcarney said in Custom events in QML:
It looks like it prioritizes by last created Item. At least for eventFilter it does.
https://doc.qt.io/qt-6/qobject.html#installEventFilter:
If multiple event filters are installed on a single object, the filter that was installed last is activated first.