MouseEvent QML Type▲
-
Import Statement: import QtQuick
-
Group: MouseEvent is part of qtquick-input-events
Detailed Description▲
The position of the mouse can be found via the x and y properties. The button that caused the event is available via the button property.
See Also▲
See also MouseArea
Property Documentation▲
[read-only] x : real▲
[read-only] y : real
These properties hold the coordinates of the position supplied by the mouse event.
accepted : bool▲
Setting accepted to true prevents the mouse event from being propagated to items below this item.
Generally, if the item acts on the mouse event then it should be accepted so that items lower in the stacking order do not also respond to the same event.
[read-only] button : enumeration▲
[read-only] buttons : int▲
It contains a bitwise combination of:
[read-only, since 5.11] flags : int▲
This property holds the flags that provide additional information about the mouse event.
-
Qt.MouseEventCreatedDoubleClick - Indicates that Qt has created a double click event from this event. This flag is set in the event originating from a button press, and not in the resulting double click event.
This property was introduced in Qt 5.11.
[read-only] modifiers : int▲
This property holds the keyboard modifier flags that existed immediately before the event occurred.
It contains a bitwise combination of:
-
Qt.NoModifier - No modifier key is pressed.
-
Qt.ShiftModifier - A Shift key on the keyboard is pressed.
-
Qt.ControlModifier - A Ctrl key on the keyboard is pressed.
-
Qt.AltModifier - An Alt key on the keyboard is pressed.
-
Qt.MetaModifier - A Meta key on the keyboard is pressed.
-
Qt.KeypadModifier - A keypad button is pressed.
For example, to react to a Shift key + Left mouse button click:
MouseArea
{
onClicked
:
(mouse)=&
gt; {
if
((mouse.button ==
Qt.LeftButton) &
amp;&
amp; (mouse.modifiers &
amp; Qt.ShiftModifier))
doSomething();
}
}
[read-only] wasHeld : bool▲
This property is true if the mouse button has been held pressed longer than the threshold (800ms).
Obsolete Members for MouseEvent▲
The following members of QML type MouseEvent are deprecated. We strongly advise against using them in new code.
Obsolete Property Documentation▲
[read-only, since 5.7] source : int▲
This property is deprecated since 6.2. We strongly advise against using it in new code.
Use 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:
-
Qt.MouseEventNotSynthesized - The most common value. On platforms where such information is available, this value indicates that the event represents a genuine mouse event from the system.
-
Qt.MouseEventSynthesizedBySystem - Indicates that the mouse event was synthesized from a touch or tablet event by the platform.
-
Qt.MouseEventSynthesizedByQt - Indicates that the mouse event was synthesized from an unhandled touch or tablet event by Qt.
-
Qt.MouseEventSynthesizedByApplication - Indicates that the mouse event was synthesized by the application. This allows distinguishing application-generated mouse events from the ones that are coming from the system or are synthesized by Qt.
For example, to react only to events which come from an actual mouse:
MouseArea
{
onPressed
:
(mouse)=&
gt; {
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.
This property was introduced in Qt 5.7.