zoukankan      html  css  js  c++  java
  • Qt 模拟鼠标点击(QApplication::sendEvent(ui->pushbutton, &event0);)

    QPoint pos(0,0);
    QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    QApplication::sendEvent(ui->pushbutton, &event0);

    QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    QApplication::sendEvent(ui->pushbutton, &event1);
    1
    2
    3
    4
    5
    6
    sendEvent 是发送事件函数,第一个参数是接收该事件的元对象,第二个参数是要发送的事件;
    QMouseEvent用来构造一个模拟的鼠标事件,构造函数中定义了事件的类型为按压或者是释放,pos参数是用来指定在接收该事件的元对象的事件发生位置,例子中就是指定了在按钮的(0,0)位置接收该点击事件;
    QPos定义位置。

    对于QLineEdit这种部件,可以通过setFocus()函数先让部件获得角点,再把sendEvent()中的接收对象换成QWidget::focusWidget();
    ---------------------
    作者:蜗牛在听雨
    来源:CSDN
    原文:https://blog.csdn.net/omg_orange/article/details/75803977
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    [原]将工程由VC6迁移到VS2005
    [原]DirectDraw视频播放要点
    [原]代码优化学习笔记
    [原]Linux文件交换
    [原]计划
    [原]写在2006年的最后一天
    [原]技术发展规划
    FindBugs的安装和使用
    VirtualBox常用命令
    eclipse中统计代码行数
  • 原文地址:https://www.cnblogs.com/findumars/p/10344545.html
Copyright © 2011-2022 走看看