QNativeGestureEvent 类

QNativeGestureEvent 类包含手势事件的描述参数。 更多...

头: #include <QNativeGestureEvent>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QSinglePointEvent

公共函数

QNativeGestureEvent (Qt::NativeGestureType type , const QPointingDevice * device , int fingerCount , const QPointF & localPos , const QPointF & scenePos , const QPointF & globalPos , qreal value , const QPointF & delta , quint64 sequenceId = UINT64_MAX)
QPointF delta () const
int fingerCount () const
Qt::NativeGestureType gestureType () const
qreal value () const

详细描述

Native gesture events are generated by the operating system, typically by interpreting trackpad touch events. Gesture events are high-level events such as zoom, rotate or pan. Several types hold incremental values: that is, value () 和 delta () provide the difference from the previous event to the current event.

事件类型 描述 Touch sequence
Qt::ZoomNativeGesture 放大增量 (以百分比为单位)。 macOS and Wayland: Two-finger pinch.
Qt::SmartZoomNativeGesture 布尔放大状态。 macOS:2 指双击 (触摸板)/单指双击 (魔法鼠标)。
Qt::RotateNativeGesture 旋转增量 (以度为单位)。 macOS and Wayland: Two-finger rotate.
Qt::SwipeNativeGesture Swipe angle in degrees. macOS: Configurable in trackpad settings.
Qt::PanNativeGesture Displacement delta in pixels. Wayland: Three or more fingers moving as a group, in any direction.

此外,BeginNativeGesture 和 EndNativeGeature 在手势事件流之前和之后发送:

BeginNativeGesture ZoomNativeGesture ZoomNativeGesture ZoomNativeGesture EndNativeGesture

The event stream may include interleaved gestures of different types: for example the two-finger pinch gesture generates a stream of Zoom and Rotate events, and PanNativeGesture may sometimes be interleaved with those, depending on the platform.

Other types are standalone events: SmartZoomNativeGesture and SwipeNativeGesture occur only once each time the gesture is detected.

注意: On a touchpad, moving two fingers as a group (the two-finger flick gesture) is usually reserved for scrolling; in that case, Qt generates QWheelEvents. This is the reason that three or more fingers are needed to generate a PanNativeGesture.

另请参阅 Qt::NativeGestureType , QGestureEvent ,和 QWheelEvent .

成员函数文档编制

[since 6.2] QNativeGestureEvent:: QNativeGestureEvent ( Qt::NativeGestureType type , const QPointingDevice * device , int fingerCount , const QPointF & localPos , const QPointF & scenePos , const QPointF & globalPos , qreal value , const QPointF & delta , quint64 sequenceId = UINT64_MAX)

构造本机手势事件为类型 type originating from device describing a gesture at scenePos in which fingerCount fingers are involved.

localPos , scenePos and globalPos specify the gesture position relative to the receiving widget or item, window, and screen or desktop, respectively.

value has a gesture-dependent interpretation: for RotateNativeGesture or SwipeNativeGesture, it's an angle in degrees. For ZoomNativeGesture, value is an incremental scaling factor, usually much less than 1, indicating that the target item should have its scale adjusted like this: item.scale = item.scale * (1 + event.value)

For PanNativeGesture, delta gives the distance in pixels that the viewport, widget or item should be moved or panned.

注意: The delta is stored in single precision ( QVector2D ), so delta () may return slightly different values in some cases. This is subject to change in future versions of Qt.

该函数在 Qt 6.2 引入。

[since 6.2] QPointF QNativeGestureEvent:: delta () const

Returns the distance moved since the previous event, in pixels. A Pan gesture provides the distance in pixels by which the target widget, item or viewport contents should be moved.

该函数在 Qt 6.2 引入。

另请参阅 QPanGesture::delta ().

[since 6.2] int QNativeGestureEvent:: fingerCount () const

Returns the number of fingers participating in the gesture, if known. When gestureType () 是 Qt::BeginNativeGesture or Qt::EndNativeGesture , often this information is unknown, and fingerCount() returns 0 .

该函数在 Qt 6.2 引入。

Qt::NativeGestureType QNativeGestureEvent:: gestureType () const

返回手势类型。

qreal QNativeGestureEvent:: value () const

Returns the gesture value. The value should be interpreted based on the gesture type. For example, a Zoom gesture provides a scale factor delta while a Rotate gesture provides a rotation delta.

另请参阅 QNativeGestureEvent and gestureType ().