QPointingDevice Class

QPointingDevice 类描述了鼠标、触摸或平板电脑事件的源设备。更多

头文件: #include <QPointingDevice>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
Qt 6.0
继承: QInputDevice

公共类型

enum GrabTransition { GrabExclusive, UngrabExclusive, CancelGrabExclusive, GrabPassive, UngrabPassive, …, OverrideGrabPassive }
enum class PointerType { Unknown, Generic, Finger, Pen, Eraser, …, AllPointerTypes }
flags PointerTypes

公共函数

QPointingDevice(QObject *parent = nullptr)
QPointingDevice(const QString &name, qint64 id, QInputDevice::DeviceType deviceType, QPointingDevice::PointerType pointerType, QInputDevice::Capabilities capabilities, int maxPoints, int buttonCount, const QString &seatName = QString(), QPointingDeviceUniqueId uniqueId = QPointingDeviceUniqueId(), QObject *parent = nullptr)
int buttonCount() const
int maximumPoints() const
QPointingDevice::PointerType pointerType() const
QPointingDeviceUniqueId uniqueId() const

信号

void grabChanged(QObject *grabber, QPointingDevice::GrabTransition transition, const QPointerEvent *event, const QEventPoint &point) const

静态公共成员

const QPointingDevice *primaryPointingDevice(const QString &seatName = QString())

详细说明

每个QPointerEvent 都包含一个 QPointingDevice 指针,用于访问特定于设备的属性,如类型和功能。在生成任何指针事件之前,平台或通用插件有责任通过 QWindowSystemInterface 注册可用的指向设备。应用程序无需实例化该类,只需访问QPointerEvent::device() 指向的全局实例即可。

成员类型文档

enum QPointingDevice::GrabTransition

该枚举表示从一个对象(可能是nullptr )到另一个对象(可能是nullptr )的独占或被动抓取的转换。它作为QPointingDevice::grabChanged() 信号的参数发出。

有效值为

常量说明
QPointingDevice::GrabExclusive0x10QPointerEvent::setExclusiveGrabber() 之后发出。
QPointingDevice::UngrabExclusive0x20当抓取器设置为nullptr 时,在QPointerEvent::setExclusiveGrabber() 之后发出,通知抓取已正常结束。
QPointingDevice::CancelGrabExclusive0x30当抓取器设置为其他对象时,在QPointerEvent::setExclusiveGrabber() 之后发出,通知旧抓取器的抓取已被 "窃取"。
QPointingDevice::GrabPassive0x01QPointerEvent::addPassiveGrabber() 之后发出。
QPointingDevice::UngrabPassive0x02被动抓取正常终止时发出,例如在QPointerEvent::removePassiveGrabber() 之后。
QPointingDevice::CancelGrabPassive0x03被动抓取异常终止(手势被取消)时发出。
QPointingDevice::OverrideGrabPassive0x04该值目前未被使用。

枚举类 QPointingDevice::PointerType
标志 QPointingDevice::PointerTypes

该枚举表示与指向设备交互的内容。

该属性与QInputDevice::DeviceType 之间存在一些冗余。例如,如果使用的是触摸屏,那么DeviceType 就是TouchScreenPointerType 就是Finger (始终)。但在绘图板上,通常可能同时使用触控笔的两端,程序需要区分它们。因此,我们扩展了这一概念,使每个QPointerEvent 都有一个指针类型(PointerType),这样可以简化某些事件处理代码,忽略设备类型(DeviceType),仅根据指针类型做出不同反应。

有效值为

常量说明
QPointingDevice::PointerType::Unknown0指针类型未知。
QPointingDevice::PointerType::Generic0x0001鼠标或类似鼠标的东西(X11 的核心指针)。
QPointingDevice::PointerType::Finger0x0002用户的手指。
QPointingDevice::PointerType::Pen0x0004触控笔的绘图端。
QPointingDevice::PointerType::Eraser0x0008触控笔的另一端(如果另一端有虚拟橡皮擦)。
QPointingDevice::PointerType::Cursor0x0010Puck 设备上带有十字准线的透明圆圈。
QPointingDevice::PointerType::AllPointerTypes0x7FFF以上任何一种(用作默认过滤值)。

PointerTypes 类型是QFlags<PointerType> 的类型定义。它存储 PointerType 值的 OR 组合。

成员函数文档

QPointingDevice::QPointingDevice(QObject *parent = nullptr)

创建一个新的无效指向设备实例,作为parent 的子节点。

QPointingDevice::QPointingDevice(const QString &name, qint64 id, QInputDevice::DeviceType deviceType, QPointingDevice::PointerType pointerType, QInputDevice::Capabilities capabilities, int maxPoints, int buttonCount, const QString &seatName = QString(), QPointingDeviceUniqueId uniqueId = QPointingDeviceUniqueId(), QObject *parent = nullptr)

使用给定的name,deviceType,pointerType,capabilities,maxPoints,buttonCount,seatName,uniqueIdparent 创建新的指向设备实例。

int QPointingDevice::buttonCount() const

返回可检测到的设备上按钮的最大数量。

注: 属性 buttonCount 的获取函数。

[signal] void QPointingDevice::grabChanged(QObject *grabber, QPointingDevice::GrabTransition transition, const QPointerEvent *event, const QEventPoint &point) const

grabber 对象在传递event 的过程中获得或失去对point 的独占或被动抓取时,就会发出该信号。transition 会从grabber 对象的角度说明发生了什么。

注意: 从一个对象到另一个对象的抓取转换会产生两个信号,一个是通知一个对象失去了抓取,另一个是通知有另一个抓取者。在其他情况下,当过渡到非抓取状态或从非抓取状态过渡时,只发出一个信号:grabber 参数永远不会被nullptr

另请参见 QPointerEvent::setExclusiveGrabber()、QPointerEvent::addPassiveGrabber() 和QPointerEvent::removePassiveGrabber()。

int QPointingDevice::maximumPoints() const

返回可检测到的最大同时触摸点(手指)数量。

注: maximumPoints 属性的获取函数。

QPointingDevice::PointerType QPointingDevice::pointerType() const

返回指针类型。

注: 属性 pointerType 的获取函数。

[static] const QPointingDevice *QPointingDevice::primaryPointingDevice(const QString &seatName = QString())

返回给定座位seatName 上的主要指向设备(核心指针,传统上假定为鼠标)。

如果注册了多个指向设备,该函数会优先选择与给定seatName 匹配且没有其他设备作为其父设备的鼠标或触摸板。通常只有一个主设备或核心设备没有父设备。但如果找不到这样的设备,该函数就会创建一个新的虚拟 "核心指针 "鼠标。这样,Qt 就能在尚未进行输入设备发现和注册的平台上继续工作。

QPointingDeviceUniqueId QPointingDevice::uniqueId() const

返回设备的唯一 ID(实用性存疑)。

您可能更应该关注 QPointerEventPoint::uniqueId()。

注: uniqueId 属性的获取函数。

© 2025 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.