I have a Qt application (server) that receives mouse positions and state ( mouse pressed, released or mouse move) over the local network from another Qt application. I read in the mouse state and position correctly but I am not able to generate fake messages in the server app to simulate mouse move, mouse pressed events.
The server has all the logic in QGraphicsView to handle mouse move etc and everything works as expected when it gets input from a mouse on the server machine.
But once i try to generate fake mouseEvents by reading mouse position and state sent from other app, it doesn't work.
Surprisingly, if I create fake events and pass it to scene as shown below, it generates mouseMoveEvents but I want to do this for QGraphicsView as it has the logic for handling mouse in the server app.
This works :
QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
pressEvent.setScenePos(QPointF(100, 100));
pressEvent.setButton(Qt::LeftButton);
pressEvent.setButtons(Qt::LeftButton);
QApplication::sendEvent(pGraphicsScene, &pressEvent);
This doesnt work :
QMouseEvent eve( (QEvent::MouseMove), QPoint(100,100),
Qt::NoButton,
Qt::NoButton,
Qt::NoModifier );
qApp->sendEvent(this , &eve);
Can anyone help me understand why I cant generate fake events for GraphicsView and how can this be done.
Thanks
yourGraphicsView->setMouseTracking(true)
for enabling detection of mouseMove events? – epsilon