Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Eventloop/Event dispatching
Forum Updated to NodeBB v4.3 + New Features

Eventloop/Event dispatching

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 528 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlexandruS
    wrote on last edited by
    #1

    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!

    Pl45m4P 1 Reply Last reply
    0
    • A AlexandruS

      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!

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @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 like mouseDoubleClickEvent or something.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      A 1 Reply Last reply
      1
      • Pl45m4P Pl45m4

        @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 like mouseDoubleClickEvent or something.

        A Offline
        A Offline
        AlexandruS
        wrote on last edited by
        #3

        @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 via childAt(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.

        1 Reply Last reply
        0
        • I Online
          I Online
          IgKh
          wrote on last edited by
          #4

          Indeed, QGuiApplicationPrivate::processMouseEvent sends the event(s) to the top level window at the mouse position, but this has nothing to do with QMainWindow or any other widgets class - at least not directly. Window here means a QWindow object, which is the abstraction over windows of the native windowing system (which need not be actual windows with decorations etc, the meaning here is that of a drawable surface known to the native system).

          This abstraction lives in the QtGui module, so is independent of widgets. The bridge between the worlds is the private QWidgetWindow class, representing the surface of a QWidget which has one. You can have a look in QWidgetWindow::handleMouseEvent to see how it finds the final target widget for the event, but it is pretty much what you'd expect.

          P.S any top-level widget has to be backed by a QWindow, and not only QMainWindow instances can be top-level widgets. Also QDialog, but also any widget that has a suitable window flag set, or any widget without parent on which show was called.

          A 1 Reply Last reply
          3
          • I IgKh

            Indeed, QGuiApplicationPrivate::processMouseEvent sends the event(s) to the top level window at the mouse position, but this has nothing to do with QMainWindow or any other widgets class - at least not directly. Window here means a QWindow object, which is the abstraction over windows of the native windowing system (which need not be actual windows with decorations etc, the meaning here is that of a drawable surface known to the native system).

            This abstraction lives in the QtGui module, so is independent of widgets. The bridge between the worlds is the private QWidgetWindow class, representing the surface of a QWidget which has one. You can have a look in QWidgetWindow::handleMouseEvent to see how it finds the final target widget for the event, but it is pretty much what you'd expect.

            P.S any top-level widget has to be backed by a QWindow, and not only QMainWindow instances can be top-level widgets. Also QDialog, but also any widget that has a suitable window flag set, or any widget without parent on which show was called.

            A Offline
            A Offline
            AlexandruS
            wrote on last edited by
            #5

            @IgKh thanks! I think this is it. I will look further around these.

            1 Reply Last reply
            0
            • A AlexandruS has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved