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
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    CCF201503-2数字排序
    CCF201503-1图像旋转
    leetcode 13.罗马数字转整数
    Mysql中limit的用法
    网站访问量统计案例
    ServletContext(重要)
    Servlet(自己实现的Servlet)细节
    HttpServlet
    GenericServlet
    Servlet的相关类--ServletConfig(接口)
  • 原文地址:https://www.cnblogs.com/findumars/p/10344545.html
Copyright © 2011-2022 走看看