I introduce keyboard and mouse events that are sent over the network to my Qt application and use QCoreApplication::postEvent
for this. The mouse coordinates are the absolute coordinates of the screen pixel.
QMouseEvent *event = new QMouseEvent(type, QPoint(x, y), mouse_button, mouse_buttons, Qt::NoModifier); QCoreApplication::postEvent(g_qtdraw.main.widget, event);
Initially, I only had one widget (referenced by g_qtdraw.main.widget
), so I just used it as a receiver argument for postEvent
. Now my application has more than one widget, and the above code no longer does what I want.
The second widget is displayed in full screen mode, and I know that all mouse events should go to this window, but with the above code, they are still routed to the main widget.
How to choose the correct widget as the receiver (the one under the x, y coords mouse)? Is there a standard way so Qt selects the correct widget or do I need to track this myself?
change
Now I use the following, which works great (Thanks a lot to Dusty Campbell ):
QPoint pos(x, y); QWidget *receiver = QApplication::widgetAt(pos); if (receiver) { QMouseEvent *event = new QMouseEvent(type, receiver->mapFromGlobal(pos), mouse_button, mouse_buttons, Qt::NoModifier); QCoreApplication::postEvent(receiver, event); }
source share