QWaylandSeat Class
QWaylandSeat 类提供了对键盘、鼠标和触摸输入的访问。更多内容...
| 头文件: | #include <QWaylandSeat> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS WaylandCompositor) target_link_libraries(mytarget PRIVATE Qt6::WaylandCompositor) |
| qmake: | QT += waylandcompositor |
| 在 QML 中: | WaylandSeat |
| 继承自: | QWaylandObject |
公共类型
| enum | CapabilityFlag { Pointer, Keyboard, Touch, DefaultCapabilities } |
| flags | CapabilityFlags |
属性
公共函数
| QWaylandSeat(QWaylandCompositor *compositor, QWaylandSeat::CapabilityFlags capabilityFlags = DefaultCapabilities) | |
| virtual | ~QWaylandSeat() override |
| QWaylandSeat::CapabilityFlags | capabilities() const |
| QWaylandCompositor * | compositor() const |
| QWaylandDrag * | drag() const |
| virtual void | initialize() |
| bool | isInitialized() const |
| QWaylandKeyboard * | keyboard() const |
| QWaylandSurface * | keyboardFocus() const |
| QWaylandKeymap * | keymap() |
| QWaylandView * | mouseFocus() const |
| QWaylandPointer * | pointer() const |
| void | sendFullKeyEvent(QKeyEvent *event) |
| void | sendFullTouchEvent(QWaylandSurface *surface, QTouchEvent *event) |
| void | sendKeyEvent(int qtKey, bool pressed) |
| void | sendKeyPressEvent(uint code) |
| void | sendKeyReleaseEvent(uint code) |
| void | sendMouseMoveEvent(QWaylandView *view, const QPointF &localPos, const QPointF &outputSpacePos = QPointF()) |
| void | sendMousePressEvent(Qt::MouseButton button) |
| void | sendMouseReleaseEvent(Qt::MouseButton button) |
| void | sendMouseWheelEvent(Qt::Orientation orientation, int delta) |
| void | sendTouchCancelEvent(QWaylandClient *client) |
| void | sendTouchFrameEvent(QWaylandClient *client) |
| uint | sendTouchPointEvent(QWaylandSurface *surface, int id, const QPointF &point, Qt::TouchPointState state) |
| uint | sendTouchPointMoved(QWaylandSurface *surface, int id, const QPointF &position) |
| uint | sendTouchPointPressed(QWaylandSurface *surface, int id, const QPointF &position) |
| uint | sendTouchPointReleased(QWaylandSurface *surface, int id, const QPointF &position) |
(since 6.7) void | sendUnicodeKeyPressEvent(uint unicode) |
(since 6.7) void | sendUnicodeKeyReleaseEvent(uint unicode) |
| bool | setKeyboardFocus(QWaylandSurface *surface) |
| void | setMouseFocus(QWaylandView *view) |
| QWaylandTouch * | touch() const |
信号
| void | cursorSurfaceRequest(QWaylandSurface *surface, int hotspotX, int hotspotY) |
| void | keyboardFocusChanged(QWaylandSurface *newFocus, QWaylandSurface *oldFocus) |
| void | mouseFocusChanged(QWaylandView *newFocus, QWaylandView *oldFocus) |
静态公共成员
| QWaylandSeat * | fromSeatResource(struct wl_resource *resource) |
成员类型文档
enum QWaylandSeat::CapabilityFlag
flags QWaylandSeat::CapabilityFlags
此枚举类型描述了QWaylandSeat 的功能。
| 常量 | 值 | 描述 |
|---|---|---|
QWaylandSeat::Pointer | 0x01 | QWaylandSeat 支持指针输入。 |
QWaylandSeat::Keyboard | 0x02 | QWaylandSeat 支持键盘输入。 |
QWaylandSeat::Touch | 0x04 | QWaylandSeat 支持触摸输入。 |
QWaylandSeat::DefaultCapabilities | Pointer | Keyboard | Touch | QWaylandSeat 具有默认功能。 |
CapabilityFlags 类型是QFlags<CapabilityFlag> 的 typedef。它存储 CapabilityFlag 值的按“或”运算组合。
属性文档
[read-only] drag : QWaylandDrag* const
该属性用于处理拖放操作,并在操作开始和结束时发送信号。该属性还存储了诸如用户拖动鼠标时鼠标光标下方应显示哪张图片等详细信息。
访问函数:
| QWaylandDrag * | drag() const |
[read-only] keymap : QWaylandKeymap* const
该属性存储键映射对象。
键映射提供了一种将实际的键扫描码转换为有意义值的方法。例如,如果您使用的是挪威语布局的键映射,字母 L 右侧的键会输出 Ø。
键位映射还可用于自定义键功能,例如指定是否应交换 Control 键和 CAPS LOCK 键的位置等。
访问函数:
| QWaylandKeymap * | keymap() |
成员函数文档
QWaylandSeat::QWaylandSeat(QWaylandCompositor *compositor, QWaylandSeat::CapabilityFlags capabilityFlags = DefaultCapabilities)
根据给定的compositor 和capabilityFlags 创建一个QWaylandSeat。
[override virtual noexcept] QWaylandSeat::~QWaylandSeat()
摧毁了QWaylandSeat
QWaylandSeat::CapabilityFlags QWaylandSeat::capabilities() const
返回此QWaylandSeat 的特性标志。
QWaylandCompositor *QWaylandSeat::compositor() const
返回此QWaylandSeat 的合成器。
[signal] void QWaylandSeat::cursorSurfaceRequest(QWaylandSurface *surface, int hotspotX, int hotspotY)
当客户端请求将特定的surface 设为鼠标光标时,会触发此信号。例如,当用户将鼠标悬停在某个表面上时,若希望光标变为调整大小箭头。
hotspotX 和hotspotY 都是相对于指针表面左上角的偏移量,点击操作应发生在该位置。例如,如果请求的指针表面是一个箭头,这些参数就表示箭头尖端在该表面上的位置。
QWaylandDrag *QWaylandSeat::drag() const
返回此QWaylandSeat 的拖拽对象。
注意: 这是 drag 属性的获取 函数。
[static] QWaylandSeat *QWaylandSeat::fromSeatResource(struct wl_resource *resource)
返回与resource 对应的QWaylandSeat 。resource 的类型应为wl_seat。
[virtual] void QWaylandSeat::initialize()
初始化座椅中与构造函数中设置的功能,或通过 setCapabilities() 设置的功能相对应的部分。
注意:通常情况下 ,在创建 seat 和 compositor 之后,该函数会自动被调用,因此通常无需手动调用它。
bool QWaylandSeat::isInitialized() const
如果QWaylandSeat 已初始化,则返回true;否则返回false。
值true 表示客户端现在可以开始使用该席位了。
QWaylandKeyboard *QWaylandSeat::keyboard() const
返回此输入设备的键盘。
QWaylandSurface *QWaylandSeat::keyboardFocus() const
返回当前获得焦点、用于键盘输入的界面。
另请参阅 setKeyboardFocus()。
[signal] void QWaylandSeat::keyboardFocusChanged(QWaylandSurface *newFocus, QWaylandSurface *oldFocus)
当调用setKeyboardFocus() 时会发出此信号。
newFocus 该参数表示当前获得键盘焦点的界面;若无界面获得焦点,则返回nullptr 。oldFocus 表示当前失去键盘焦点的界面;若无界面拥有焦点,则返回nullptr 。
QWaylandKeymap *QWaylandSeat::keymap()
返回此QWaylandSeat 的键映射对象。
注意: 这是 keymap 属性的获取器 函数。
QWaylandView *QWaylandSeat::mouseFocus() const
返回当前获得鼠标焦点的视图。
另请参阅 ` setMouseFocus()`。
[signal] void QWaylandSeat::mouseFocusChanged(QWaylandView *newFocus, QWaylandView *oldFocus)
当鼠标焦点从oldFocus 切换到newFocus 时,会触发此信号。
QWaylandPointer *QWaylandSeat::pointer() const
返回此QWaylandSeat 的设备指针。
void QWaylandSeat::sendFullKeyEvent(QKeyEvent *event)
将event 发送至键盘设备。
注意: event 应 与当前映射中的实际键盘键相对应。例如,Qt::Key_Exclam 通常并非独立的按键:在大多数键盘上,感叹号是通过 Shift + 1 组合键输出的。在这种情况下,若要发送感叹号按键事件,请使用QKeyEvent(QEvent::KeyPress, Qt::Key_1, Qt::ShiftModifier) 。
void QWaylandSeat::sendFullTouchEvent(QWaylandSurface *surface, QTouchEvent *event)
将event 发送到触摸设备上的指定surface 。
警告:此 API 会在将QEventPoint::id() 发送至客户端之前,自动将其映射为一个顺序 ID。因此,不应将其与使用显式 ID 的其他 API 结合使用,否则可能会发生 ID 冲突。
[invokable] void QWaylandSeat::sendKeyEvent(int qtKey, bool pressed)
向键盘设备发送键qtKey 的按下事件(若pressed 的值为true )或释放事件(若pressed 的值为false )。
注意:此 函数不支持需要修饰键的键事件,例如Qt::Key_Exclam 。请改用sendFullKeyEvent 。
注意:此 函数可通过元对象系统和 QML 调用。请参阅Q_INVOKABLE 。
void QWaylandSeat::sendKeyPressEvent(uint code)
向键盘设备发送一个键按事件,键值为code 。
void QWaylandSeat::sendKeyReleaseEvent(uint code)
向键盘设备发送一个键释放事件,该事件的键为code 。
void QWaylandSeat::sendMouseMoveEvent(QWaylandView *view, const QPointF &localPos, const QPointF &outputSpacePos = QPointF())
将鼠标焦点设置为view ,并向指针设备发送一个鼠标移动事件,其中本地位置为localPos ,输出空间位置为outputSpacePos 。
void QWaylandSeat::sendMousePressEvent(Qt::MouseButton button)
向QWaylandSeat 的指针设备发送button 的鼠标按下事件。
void QWaylandSeat::sendMouseReleaseEvent(Qt::MouseButton button)
向QWaylandSeat 的指针设备发送button 的鼠标释放事件。
void QWaylandSeat::sendMouseWheelEvent(Qt::Orientation orientation, int delta)
向QWaylandSeat 的指针设备发送鼠标滚轮事件,并传入给定的orientation 和delta 。
[invokable] void QWaylandSeat::sendTouchCancelEvent(QWaylandClient *client)
向client 的触摸设备发送一个取消事件。
注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。
[invokable] void QWaylandSeat::sendTouchFrameEvent(QWaylandClient *client)
向client 的触摸设备发送一个帧事件,以指示一系列触摸上、下和移动事件的结束。
注意: 可通过元对象系统和 QML 调用此 函数。请参阅Q_INVOKABLE 。
uint QWaylandSeat::sendTouchPointEvent(QWaylandSurface *surface, int id, const QPointF &point, Qt::TouchPointState state)
向触摸设备上的surface 发送触摸点事件,并传入指定的id 、point 和state 。
警告: 不应将此 API 与使用QWaylandQuickItem::touchEventsEnabled 或sendFullTouchEvent 转发触摸事件的功能结合使用,否则可能会导致触摸 ID 冲突。
返回触摸抬起或触摸按下事件的序列号。
[invokable] uint QWaylandSeat::sendTouchPointMoved(QWaylandSurface *surface, int id, const QPointF &position)
为位于surface 上的触点id (位置为position )发送一个触摸移动事件。
注意: 在完成触摸事件的发送后,您 需要发送一个触摸帧事件。
警告:此 API 不应与使用QWaylandQuickItem::touchEventsEnabled 或sendFullTouchEvent 转发触摸事件结合使用,因为这可能会导致触摸 ID 冲突。
返回触摸运动事件的序列号。
注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。
[invokable] uint QWaylandSeat::sendTouchPointPressed(QWaylandSurface *surface, int id, const QPointF &position)
为位于surface 且坐标为position 的触点id 发送一个触摸按下事件。
注意: 在完成触摸事件的发送后,您 需要发送一个触摸帧事件。
警告:此 API 不应与使用QWaylandQuickItem::touchEventsEnabled 或sendFullTouchEvent 转发触摸事件结合使用,因为这可能会导致触摸 ID 冲突。
返回触摸下压事件的序列号。
注意:此 函数可通过元对象系统和 QML 调用。请参阅Q_INVOKABLE 。
[invokable] uint QWaylandSeat::sendTouchPointReleased(QWaylandSurface *surface, int id, const QPointF &position)
为位于surface 且位置为position 的触点id 发送一个触摸释放事件。
注意: 在完成触摸事件的发送后,您 需要发送一个触摸帧事件。
警告: 不应将此 API 与使用QWaylandQuickItem::touchEventsEnabled 或sendFullTouchEvent 转发触摸事件结合使用,因为这可能会导致触摸 ID 冲突。
返回触摸释放事件的序列号。
注意:此 函数可通过元对象系统和 QML 调用。请参阅Q_INVOKABLE 。
[invokable, since 6.7] void QWaylandSeat::sendUnicodeKeyPressEvent(uint unicode)
通过文本输入协议发送 UCS4unicode 的按键事件。
注意: 如果客户端不支持合成器所支持的文本输入协议,则此 函数将无法正常工作。
注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。
该函数于 Qt 6.7 中引入。
另请参阅 sendKeyEvent 。
[invokable, since 6.7] void QWaylandSeat::sendUnicodeKeyReleaseEvent(uint unicode)
通过文本输入协议发送 UCS4unicode 的键释放事件。
注意: 如果客户端不支持合成器所支持的文本输入协议,则此 函数将无法正常工作。
注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。
该函数于 Qt 6.7 中引入。
另请参阅 sendKeyEvent 。
bool QWaylandSeat::setKeyboardFocus(QWaylandSurface *surface)
将当前键盘焦点设置为surface 。返回一个布尔值,表示操作是否成功。
另请参阅 keyboardFocus()。
void QWaylandSeat::setMouseFocus(QWaylandView *view)
将当前鼠标焦点设置为view 。
另请参阅 mouseFocus()。
QWaylandTouch *QWaylandSeat::touch() const
返回此QWaylandSeat 的触摸设备。
© 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.