Eventloop/Event dispatching
-
Hello!
I know the events are being dispatched to the low level widgets, then depending on their acceptance, they bubble up in the parent tree.
There is this piece of information that puzzles me and can't seem to find the answer:
How does an event, lets say mouseMove or mousePressed, make its way from the QGuiApplication::exec/EventLoop to the appropriate widget, be it a QPushButton?I tried to follow the source code in QGuiApplication and found this QGuiApplicationPrivate::processMouseEvent.
In here I see that it queries the top level window under the mouse coords.
Then went over to the QMainWindow implementation but I can't seem to find specific handling for mouse events.Can you give me some pointers or brief description on how an event loop event actually reaches the appropriate widget handler?
Thanks!
-
@AlexandruS said in Eventloop/Event dispatching:
Can you give me some pointers
Read here.
And this sections says that key and mouse events originate from the window system that you are using. Then it's the same as for any other events. The event is created and send to the event location where it happened. The widget's
event()
handler receives it first, then calling the appropriate more specific handlers likemouseDoubleClickEvent
or something. -
@Pl45m4 Thanks for your reply!
I get this part, until now I took it for granted, but I want to have a better understanding of the under the hood mechanisms.
Eg from the docs:
When an event occurs, Qt creates an event object to represent it by constructing an instance of the appropriate QEvent subclass, and delivers it to a particular instance of QObject (or one of its subclasses) by calling its event() function.
So if I have let's say 3 buttons, how does Qt know for which of them the os/native event is intended?
Does it query child widgets viachildAt(some coords)
on the active window?And similarly for key press events, does it go from top level window and finds the child widget that currently has focus?
This delivery of the event is the thing that puzzles me, how does it pick the exact widget to call
event()
on.