qt模拟鼠标事件

模拟鼠标事件

1、模拟鼠标按下事件

cpp 复制代码
        QPoint p = this->rect().center();
        QMouseEvent *pressEvent = new QMouseEvent(QEvent::MouseButtonPress,
                                                  p,
                                                  Qt::LeftButton,
                                                  Qt::LeftButton,
                                                  Qt::NoModifier);
        mousePressEvent(pressEvent);

2、模拟鼠标松开事件

cpp 复制代码
QMouseEvent *releaseEvent = new QMouseEvent(QEvent::MouseButtonRelease,
                                                    p,
                                                    Qt::LeftButton,
                                                    Qt::LeftButton,
                                                    Qt::NoModifier);
mouseReleaseEvent(releaseEvent);

3、模拟鼠标点击事件

按顺序模拟1、2的事件,代码如下:

cpp 复制代码
mousePressEvent(pressEvent);
mouseReleaseEvent(releaseEvent);

4、模拟鼠标移动事件

cpp 复制代码
QMouseEvent *moveEvent = new QMouseEvent(QEvent::MouseMove,
                                         p,
                                         Qt::LeftButton,
                                         Qt::LeftButton,
                                         Qt::NoModifier);
mousePressEvent(pressEvent);
mouseReleaseEvent(releaseEvent);
mouseMoveEvent(moveEvent); //新增移动事件刷新画线和十字线
相关推荐
多加点辣也没关系1 小时前
JavaScript|第4章:类型转换
开发语言·javascript
聪慧的水蜜桃1 小时前
【YFIOs】用C#开发硬件之设备上云
开发语言·c#
yqcoder1 小时前
httpOnly 是什么,又有什么用?
开发语言·前端·javascript
wuqingshun3141592 小时前
重写equals而不重写hashCode,会出什么问题?
java·开发语言
飞猪~2 小时前
LangChain python 版本 第一集
开发语言·python·langchain
李燚4 小时前
Go 项目怎么组织:DDD 4 层 vs MVC vs 脚本式
开发语言·golang·mvc·ddd·agent框架·eino
2zcode5 小时前
免费开源项目文档:基于MATLAB图像处理的啤酒瓶口缺陷检测系统设计与实现
开发语言·图像处理·matlab
人工智能时代 准备好了吗5 小时前
AI回答内容进入率监测:引用识别、文本匹配与语义判断
开发语言·人工智能·python
LONGZETECH5 小时前
新能源汽车动力电池检测仿真教学系统:C/S 分层架构与数字化实训落地全解析
大数据·c语言·开发语言·人工智能·架构·系统架构·汽车
郝学胜-神的一滴5 小时前
中级OpenGL教程 013:渲染器类架构设计与逐帧渲染流程详解
开发语言·c++·unity·游戏引擎·图形渲染·opengl·unreal