The following members of QML type MouseEvent 被弃用。 提供它们是为使旧源代码能继续工作。强烈建议不要在新代码中使用它们。
(deprecated since 6.2)
[read-only] source : int |
This property is deprecated since 6.2. We strongly advise against using it in new code.
使用 input handlers with acceptedDevices set.
This property holds the source of the mouse event.
The mouse event source can be used to distinguish between genuine and artificial mouse events. When using other pointing devices such as touchscreens and graphics tablets, if the application does not make use of the actual touch or tablet events, mouse events may be synthesized by the operating system or by Qt itself.
The value can be one of:
For example, to react only to events which come from an actual mouse:
MouseArea { onPressed: (mouse)=> { if (mouse.source !== Qt.MouseEventNotSynthesized) mouse.accepted = false } onClicked: doSomething() }
If the handler for the press event rejects the event, it will be propagated further, and then another Item underneath can handle synthesized events from touchscreens. For example, if a Flickable is used underneath (and the MouseArea is not a child of the Flickable), it can be useful for the MouseArea to handle genuine mouse events in one way, while allowing touch events to fall through to the Flickable underneath, so that the ability to flick on a touchscreen is retained. In that case the ability to drag the Flickable via mouse would be lost, but it does not prevent Flickable from receiving mouse wheel events.