本页内容

QInputEvent Class

QInputEvent 类是描述用户输入的事件的基类。更多内容...

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

QContextMenuEvent、QKeyEvent 以及QPointerEvent

公共函数

(since 6.0) const QInputDevice *device() const
QInputDevice::DeviceType deviceType() const
Qt::KeyboardModifiers modifiers() const
quint64 timestamp() const

受保护函数

QInputEvent(QInputEvent &&)
QInputEvent &operator=(QInputEvent &&)
QInputEvent &operator=(const QInputEvent &other)

详细说明

成员函数文档

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

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

[since 6.0] const QInputDevice *QInputEvent::device() const

返回生成原始事件的源设备。

对于合成事件(例如由触摸事件生成的鼠标事件),device() 仍会返回触摸屏设备,以便您能够识别该事件并非来自真实的鼠标。因此,mouseEvent.source()->type() != QInputDevice::DeviceType::Mouse 是 Qt 5 中表达式mouseEvent.source() == Qt::MouseEventSynthesizedByQt 的一个可能替代方案。

该函数在 Qt 6.0 中引入。

另请参阅 QPointerEvent::pointingDevice()。

QInputDevice::DeviceType QInputEvent::deviceType() const

返回生成该事件的设备类型。

Qt::KeyboardModifiers QInputEvent::modifiers() const

返回事件发生前瞬间存在的键盘修饰符标志。

另请参阅 QGuiApplication::keyboardModifiers()。

quint64 QInputEvent::timestamp() const

返回窗口系统为此事件生成的时间戳。该时间戳通常以毫秒为单位,从某个任意时间点开始计算,例如系统启动时。

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

将other 按移动赋值方式赋值给此QInputEvent 实例。此函数已被删除。

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

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

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