I want to simulate mouse Event in my Qt WebEngine app.
I use PyQt5.8 , QT5.8.
This is my code:
def mou
For Qt 5.8 running the following code:
void LeftMouseClick(QWidget* eventsReciverWidget, QPoint clickPos)
{
QMouseEvent *press = new QMouseEvent(QEvent::MouseButtonPress,
clickPos,
Qt::LeftButton,
Qt::MouseButton::NoButton,
Qt::NoModifier);
QCoreApplication::postEvent(eventsReciverWidget, press);
// Some delay
QTimer::singleShot(300, [clickPos, eventsReciverWidget]() {
QMouseEvent *release = new QMouseEvent(QEvent::MouseButtonRelease,
clickPos,
Qt::LeftButton,
Qt::MouseButton::NoButton,
Qt::NoModifier);
QCoreApplication::postEvent(eventsReciverWidget, release);
}));
}
QWebEngineView webView = new QWebEngineView();
// You need to find the first child widget of QWebEngineView. It can accept user input events.
QWidget* eventsReciverWidget = nullptr;
foreach(QObject* obj, webView->children())
{
QWidget* wgt = qobject_cast<QWidget*>(obj);
if (wgt)
{
eventsReciverWidget = wgt;
break;
}
}
QPoint clickPos(100, 100);
LeftMouseClick(eventsReciverWidget, clickPos);