1、模拟鼠标按下事件
QPoint p = this->rect().center();
QMouseEvent *pressEvent = new QMouseEvent(QEvent::MouseButtonPress,
p,
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier);
mousePressEvent(pressEvent);
2、模拟鼠标松开事件
QMouseEvent *releaseEvent = new QMouseEvent(QEvent::MouseButtonRelease,
p,
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier);
mouseReleaseEvent(releaseEvent);
3、模拟鼠标点击事件
按顺序模拟1、2的事件,代码如下:
mousePressEvent(pressEvent);
mouseReleaseEvent(releaseEvent);
4、模拟鼠标移动事件
QMouseEvent *moveEvent = new QMouseEvent(QEvent::MouseMove,
p,
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier);
mousePressEvent(pressEvent);
mouseReleaseEvent(releaseEvent);
mouseMoveEvent(moveEvent); //新增移动事件刷新画线和十字线