没有合适的资源?快使用搜索试试~ 我知道了~
Qt模拟鼠标点击
3星 · 超过75%的资源 需积分: 46 79 下载量 155 浏览量
2013-07-30
18:01:11
上传
评论 1
收藏 1020B TXT 举报
温馨提示
试读
2页
Qt模拟鼠标点击,用来自己备忘的。如有需要可以下载。
资源推荐
资源详情
资源评论
void CMainDlg::doClickLow1()
{
//QMetaObject::invokeMethod(this, "doClickLow2", Qt::AutoConnection); //doClickLow2执行完了才执行doClickLow1, 相当于 SendMessage
//emit clickLow2(); //doClickLow2执行完了才执行doClickLow1, 相当于 SendMessage
//doClickLow1执行 再执行doClickLow2, 相当于 PostMessage
QMouseEvent* press=new QMouseEvent(QEvent::MouseButtonPress,QPoint(0,0), Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);
QApplication::postEvent(pushButtonLow2,press);
QMouseEvent* release=new QMouseEvent(QEvent::MouseButtonRelease,QPoint(0,0),Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);
QApplication::postEvent(pushButtonLow2,release);
listWidgetShowMsg->addItem(QObject::tr("doClickLow1"));
}
void CMainDlg::doClickLow2()
{
QTest::qSleep(500);
listWidgetShowMsg->addItem(QObject::tr("doClickLow2"));
}
5.3 使用sendEvent时,参数 event,必须是局部变量,因为sendEvent不负责对event的删除。而postEvent的event参数,则必须是 new分配的heap对象,post完了后会自动删除。
{
//QMetaObject::invokeMethod(this, "doClickLow2", Qt::AutoConnection); //doClickLow2执行完了才执行doClickLow1, 相当于 SendMessage
//emit clickLow2(); //doClickLow2执行完了才执行doClickLow1, 相当于 SendMessage
//doClickLow1执行 再执行doClickLow2, 相当于 PostMessage
QMouseEvent* press=new QMouseEvent(QEvent::MouseButtonPress,QPoint(0,0), Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);
QApplication::postEvent(pushButtonLow2,press);
QMouseEvent* release=new QMouseEvent(QEvent::MouseButtonRelease,QPoint(0,0),Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);
QApplication::postEvent(pushButtonLow2,release);
listWidgetShowMsg->addItem(QObject::tr("doClickLow1"));
}
void CMainDlg::doClickLow2()
{
QTest::qSleep(500);
listWidgetShowMsg->addItem(QObject::tr("doClickLow2"));
}
5.3 使用sendEvent时,参数 event,必须是局部变量,因为sendEvent不负责对event的删除。而postEvent的event参数,则必须是 new分配的heap对象,post完了后会自动删除。
资源评论
- Waynev2014-05-27不能使用。
- xinlimaolin2014-06-24不是工程,是text文档,不太会用
- 吴永康2014-09-18虽然不是我想要的,但是东西还可以
- lylyly162014-04-01该使用方法未试验成功
- chen12nan2014-01-09不是我想要的。有点挂羊头卖狗肉
rain820804
- 粉丝: 0
- 资源: 33
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功