本页内容

QNativeGestureEvent Class

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

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

公共函数

(since 6.2) 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)
(since 6.2) QPointF delta() const
(since 6.2) int fingerCount() const
Qt::NativeGestureType gestureType() const
qreal value() const

受保护函数

QNativeGestureEvent(QNativeGestureEvent &&)
QNativeGestureEvent &operator=(QNativeGestureEvent &&)
QNativeGestureEvent &operator=(const QNativeGestureEvent &other)

详细说明

本机手势事件由操作系统生成,通常是通过解析触控板的触摸事件来实现的。手势事件是高级事件,例如缩放、旋转或平移。其中几种类型包含增量值:即value() 和delta() 提供了当前事件与上一个事件之间的差异。

事件类型描述触摸序列
Qt::ZoomNativeGesture以百分比表示的放大倍率变化量。macOS 和 Wayland:两指捏合。
Qt::SmartZoomNativeGesture缩放状态(布尔值)。macOS:双指双击(触控板) / 单指双击(魔术鼠标)。
Qt::RotateNativeGesture旋转增量(单位:度)。macOS 和 Wayland:两指旋转。
Qt::SwipeNativeGesture滑动角度(单位:度)。macOS:可在触控板设置中配置。
Qt::PanNativeGesture位移增量(单位:像素)。Wayland:三根或更多手指作为一个整体向任意方向移动。

此外,在手势事件流开始和结束时会分别发送 BeginNativeGesture 和 EndNativeGesture:

BeginNativeGesture ZoomNativeGesture ZoomNativeGesture ZoomNativeGesture EndNativeGesture

事件流中可能包含不同类型的手势交错出现:例如,两指捏合手势会生成一系列 Zoom 和 Rotate 事件,而 PanNativeGesture 有时也会与这些事件交错出现,具体取决于平台。

其他类型则是独立事件:每次检测到 SmartZoomNativeGesture 和 SwipeNativeGesture 手势时,它们各自仅触发一次。

注意:在 触摸板上 ,两指成组移动(两指轻扫手势)通常用于滚动;在这种情况下,Qt 会生成 QWheelEvents。这就是为什么需要三指或更多手指才能生成 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)

构建一个源地址为device 、类型为type 的原生手势事件,该事件描述了发生在scenePos 处、涉及fingerCount 个手指的手势。

坐标点localPos 、scenePos 和globalPos 分别指定了相对于接收控件或项目、窗口以及屏幕或桌面的手势位置。

value 具有与手势相关的解释:对于 RotateNativeGesture 或 SwipeNativeGesture,它表示以度为单位的角度。 对于 ZoomNativeGesture,value 是一个增量缩放因子,通常远小于 1,表示应按以下方式调整目标项的缩放比例:item.scale = item.scale * (1 + event.value)

对于 PanNativeGesture,delta 表示视口、控件或项目应移动或平移的距离(以像素为单位)。

注意: delta 以单精度(QVector2D )存储,因此在某些情况下,delta() 可能返回略有不同的值。此行为在 Qt 的未来版本中可能会发生变化。

该函数于 Qt 6.2 中引入。

[protected delete] QNativeGestureEvent::QNativeGestureEvent(QNativeGestureEvent &&)

通过移动构造一个QNativeGestureEvent 实例。该函数已被删除。

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

返回自上一次事件以来移动的距离(以像素为单位)。平移手势会提供目标小部件、项目或视口内容应移动的距离(以像素为单位)。

该函数自 Qt 6.2 起引入。

另请参阅 QPanGesture::delta()。

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

返回参与该手势的手指数量(如果已知)。当gestureType()的值为Qt::BeginNativeGesture 或Qt::EndNativeGesture 时,通常该信息未知,此时fingerCount()将返回0 。

该函数在 Qt 6.2 中引入。

Qt::NativeGestureType QNativeGestureEvent::gestureType() const

返回手势类型。

qreal QNativeGestureEvent::value() const

返回手势值。应根据手势类型来解释该值。例如,缩放手势返回缩放因子变化量,而旋转手势返回旋转角度变化量。

另请参阅 QNativeGestureEvent 和gestureType()。

[protected delete] QNativeGestureEvent &QNativeGestureEvent::operator=(QNativeGestureEvent &&)

将other 按“移动-赋值”方式赋值给此QNativeGestureEvent 实例。该函数已被删除。

[noexcept protected default] QNativeGestureEvent &QNativeGestureEvent::operator=(const QNativeGestureEvent &other)

将other 复制并赋值给此QNativeGestureEvent 实例。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.