Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-21081

Add propagateEvents property to MouseArea for easily enabling/disabling mouse event propagation

    XMLWordPrintable

Details

    • 520f9bebac742f885dc398533d91924de8793064

    Description

      QtQuick 2.0 MouseArea element has started propagating unhandled clicked, doubleClicked and pressAndHold mouse events to the other mouse areas below. This makes it possible to easily distribute mouse handling logic between multiple participants, but also may as well lead to unwanted coupling, hard-to-spot bugs and side-effects between overlapping mouse areas, especially when the user interaction is handled by both the application and stakeholder components application depends to. Many if not most interactive components (buttons, sliders, popups, views) don't want to see mouse events they receive leaking to components below.

      Currently developer can stop propagation by implementing empty signal handlers for all the propagated events: clicks, double clicks and press&holds.

      MouseArea {
          onClicked: {}
          onDoubleClicked: {}
          onPressAndHold: {}
      }
      

      which feels a bit hacky. Adding an explicit property to handle propagation would potentially result in a more readable code and make the feature more explicitly available in MouseArea API. Also, it would be nice if the propagation was an opt-in feature. Propagation is often needed for a certain use case, thus it would make sense to only enable it when developer explicitly needs it. If propagateEvents has not been defined, Qt Quick 2.0 MouseArea would continue work as in Qt Quick 1.0 and by default block clicks, double clicks and touch&hold events.

      MouseArea {
         id: delegate
         propagateEvents: true // parent known, enable propagation so that parent can handle double clicks and press&holds
         onClicked: { ...}
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            dajansen Damian Jansen (closed Nokia identity) (Inactive)
            jpetrell Joona Petrell
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes