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

相关推荐
旖-旎6 分钟前
哈希表(存在重复元素)(3)
数据结构·c++·学习·算法·leetcode·散列表
计算机安禾8 分钟前
【数据结构与算法】第39篇:图论(三):最小生成树——Prim算法与Kruskal算法
开发语言·数据结构·c++·算法·排序算法·图论·visual studio code
fish_xk13 分钟前
c++内存管理
开发语言·c++·算法
雪的季节1 小时前
qt信号槽跨线程使用时候的坑
java·开发语言·qt
yy_xzz1 小时前
【Qt 开发笔记】能扛住断电、多线程的通用配置类(移植直接用)
笔记·qt
chh5631 小时前
C++--内存管理
java·c语言·c++·windows·学习·面试
Yungoal1 小时前
C++ 标准模板库STL(Standard Template Library)
c++·哈希算法·散列表
我真不是小鱼1 小时前
cpp刷题打卡记录27——无重复字符的最长子串 & 找到字符串中所有字母的异位词
数据结构·c++·算法·leetcode
一直不明飞行1 小时前
C++:string,写法s.find(‘@‘) != s.end()是否有问题
开发语言·c++·算法
无限进步_2 小时前
【C++】重载、重写和重定义的区别详解
c语言·开发语言·c++·ide·windows·git·github