Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Custom events in QML
Forum Updated to NodeBB v4.3 + New Features

Custom events in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 834 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.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #1

    We have some alternate input devices in our system. Right now we are propagating those events via signals to underlying Items in QML. This is cumbersome and messy.

    I have started looking at the QEvent and how it works with QQuickItem. It looks like MouseArea is based upon QQuickItem and seems to capture mouse events. I have found that there is a event handler for QInputEvents already in QQuickItem. I would just base my Item similar to MouseArea. Then filter and capture my custom events based upon QInputEvent.

    What I am not understanding is how QML prioritizes those events to which Item. I don't understand how QML would know which Item should get the event first. MouseArea doesn't use the event function inputMethodEvent. There is no position associated with our devices. So I am not sure how to rectify which Item should get what events.

    C++ is a perfectly valid school of magic.

    fcarneyF 1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      I've had success interfacing a custom input device without an implicit position as a keyboard. Determining which Item received input used the well established focus mechanism. This had the added benefit of enabling cheap and readily available testing hardware.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      1
      • fcarneyF fcarney

        We have some alternate input devices in our system. Right now we are propagating those events via signals to underlying Items in QML. This is cumbersome and messy.

        I have started looking at the QEvent and how it works with QQuickItem. It looks like MouseArea is based upon QQuickItem and seems to capture mouse events. I have found that there is a event handler for QInputEvents already in QQuickItem. I would just base my Item similar to MouseArea. Then filter and capture my custom events based upon QInputEvent.

        What I am not understanding is how QML prioritizes those events to which Item. I don't understand how QML would know which Item should get the event first. MouseArea doesn't use the event function inputMethodEvent. There is no position associated with our devices. So I am not sure how to rectify which Item should get what events.

        fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        It looks like it prioritizes by last created Item. At least for eventFilter it does. I have used properties such as "enabled" and "composePropagatedEvents" to control scoping a bit from the QML side. I also made it so that my signal handlers in QML (connections made by using on<Signal> methods) are detected and used if they exist. If not they are ignored. I even implemented the "accepted" feedback as well for determining propagation. I modeled it a lot off of the MouseArea object for inspiration.

        C++ is a perfectly valid school of magic.

        jeremy_kJ 1 Reply Last reply
        0
        • fcarneyF fcarney has marked this topic as solved on
        • fcarneyF fcarney

          It looks like it prioritizes by last created Item. At least for eventFilter it does. I have used properties such as "enabled" and "composePropagatedEvents" to control scoping a bit from the QML side. I also made it so that my signal handlers in QML (connections made by using on<Signal> methods) are detected and used if they exist. If not they are ignored. I even implemented the "accepted" feedback as well for determining propagation. I modeled it a lot off of the MouseArea object for inspiration.

          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by jeremy_k
          #4

          @fcarney said in Custom events in QML:

          It looks like it prioritizes by last created Item. At least for eventFilter it does. I have used properties such as "enabled" and "composePropagatedEvents" to control scoping a bit from the QML side. I also made it so that my signal handlers in QML (connections made by using on<Signal> methods) are detected and used if they exist. If not they are ignored. I even implemented the "accepted" feedback as well for determining propagation. I modeled it a lot off of the MouseArea object for inspiration.

          I don't understand what It is, and whether the strategy is successful.

          Is composePropagatedEvents supposed to be MouseArea.propagateComposedEvents?

          Asking a question about code? http://eel.is/iso-c++/testcase/

          fcarneyF 1 Reply Last reply
          0
          • jeremy_kJ jeremy_k

            @fcarney said in Custom events in QML:

            It looks like it prioritizes by last created Item. At least for eventFilter it does. I have used properties such as "enabled" and "composePropagatedEvents" to control scoping a bit from the QML side. I also made it so that my signal handlers in QML (connections made by using on<Signal> methods) are detected and used if they exist. If not they are ignored. I even implemented the "accepted" feedback as well for determining propagation. I modeled it a lot off of the MouseArea object for inspiration.

            I don't understand what It is, and whether the strategy is successful.

            Is composePropagatedEvents supposed to be MouseArea.propagateComposedEvents?

            fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            @jeremy_k I overrided "event" and "eventFilter" methods of a QQuickItem to capture my custom events for our hardware.

            C++ is a perfectly valid school of magic.

            1 Reply Last reply
            0
            • jeremy_kJ Offline
              jeremy_kJ Offline
              jeremy_k
              wrote on last edited by
              #6

              Thanks for the clarification.

              @fcarney said in Custom events in QML:

              It looks like it prioritizes by last created Item. At least for eventFilter it does.

              https://doc.qt.io/qt-6/qobject.html#installEventFilter:

              If multiple event filters are installed on a single object, the filter that was installed last is activated first.

              Asking a question about code? http://eel.is/iso-c++/testcase/

              1 Reply Last reply
              0

              • Login

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