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