[QT/C++]如何得知鼠标事件是由触摸事件转换而来的,使得鼠标触摸事件分离

依据来源:https://doc.qt.io/qt-5/qml-qtquick-mouseevent.html

具体是在event事件或者mouse系列事件中捕获到鼠标事件后,用如下代码判断鼠标事件是否由触摸事件转换而来的

复制代码
    if(mouseEvent->source()==Qt::MouseEventSynthesizedBySystem){
        qDebug()<<"是由触摸事件转换而来的";
    }

通过该条件的一律返回,剩下的就是不由触摸事件生成的鼠标事件,由此做到鼠标与触摸事件的分离,使得触摸事件引起的鼠标事件不再干扰判断

更多信息从依据来源中抽取出来后如下,翻译由网易翻译完成。

此属性保存鼠标事件的源。

鼠标事件源可用于区分真正的鼠标事件和人工鼠标事件。当使用其他指向设备(如触摸屏和图形平板)时,如果应用程序没有使用实际的触摸或平板事件,则鼠标事件可能由操作系统或Qt本身合成。

取值可以是:

Qt.MouseEventNotSynthesized -最常见的值。在这些信息可用的平台上,该值表示该事件代表来自系统的真正鼠标事件。

Qt.MouseEventSynthesizedBySystem -指示鼠标事件是由平台从触摸或平板事件合成的。

Qt.MouseEventSynthesizedByQt -指示鼠标事件是由Qt从未处理的触摸或平板事件合成的。

Qt.MouseEventSynthesizedByApplication-指示鼠标事件是由应用程序合成的。这允许将应用程序生成的鼠标事件与来自系统或由Qt合成的鼠标事件区分开来。

这个属性是在Qt 5.7中引入的。
This property holds the source of the mouse event.

The mouse event source can be used to distinguish between genuine and

artificial mouse events. When using other pointing devices such as

touchscreens and graphics tablets, if the application does not make

use of the actual touch or tablet events, mouse events may be

synthesized by the operating system or by Qt itself.

The value can be one of:

Qt.MouseEventNotSynthesized - The most common value. On platforms

where such information is available, this value indicates that the

event represents a genuine mouse event from the system.

Qt.MouseEventSynthesizedBySystem - Indicates that the mouse event was

synthesized from a touch or tablet event by the platform.

Qt.MouseEventSynthesizedByQt - Indicates that the mouse event was

synthesized from an unhandled touch or tablet event by Qt.

Qt.MouseEventSynthesizedByApplication - Indicates that the mouse event

was synthesized by the application. This allows distinguishing

application-generated mouse events from the ones that are coming from

the system or are synthesized by Qt.

This property was introduced in Qt 5.7.

相关推荐
j_xxx404_1 小时前
Linux进程信号捕捉与操作系统运行本质深度解析
linux·运维·服务器·开发语言·c++·人工智能·ai
vx-程序开发2 小时前
基于机器学习的动漫可视化系统的设计与实现-计算机毕业设计源码08339
java·c++·spring boot·python·spring·django·php
啊董dong3 小时前
noi-2026年5月12号小测验
数据结构·c++·算法
小短腿的代码世界3 小时前
Qt国际化深度解析:从源码到企业级多语言实践
java·数据库·qt
咩咦3 小时前
C++学习笔记24:构造函数初始化列表
c++·学习笔记·类和对象·构造函数·初始化列表·const引用
计算机安禾4 小时前
【c++面向对象编程】第43篇:可变参数模板(C++11):优雅处理不定长参数
java·开发语言·c++
10岁的博客4 小时前
C++ 进制转换:通用 a 进制转 b 进制(2-36进制)题解
开发语言·c++
小贾要学习5 小时前
【Linux】基于自定义TCP协议的日期计算器
linux·网络·c++·网络协议·tcp/ip
YsyaaabB5 小时前
ACM 模式通用代码模板
java·c++·python·算法
我命由我123455 小时前
C++ - 面向对象 - 析构函数
android·c语言·开发语言·c++·visualstudio·visual studio·android runtime