Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Bug ? MouseEvent generates Canceled signal if not accepted

    QML and Qt Quick
    2
    2
    765
    Loading More Posts
    • 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.
    • P
      profi-S last edited by

      Hi,
      I tried to make two overlapped MouseAreas processing the same signals, but seems MouseArea does not propagate signals by default. The "documentation ":http://doc.qt.io/qt-5/qml-qtquick-mouseevent.html#accepted-prop states that mouse event has to be accepted to prevent propagation, but it is accepted also if I have just empty handler processing such signals (Pressed).
      If in onPressed() handler I set accepted to false this cause Canceled signal to be generated ! If we would follow documentation this must just propagate mouse event to another MouseArea

      Simple code for testing :
      @import QtQuick 2.0

      Item{
      width: 300
      height: 300
      Rectangle {
      width: 300
      height: 300
      color: "red"
      MouseArea{
      anchors.fill: parent
      onPressed: {

                  console.log("red pressed");
              }
              onReleased: {
                  console.log("red released");
              }
              onCanceled: {
                  console.log("red canceled");
              }
              onPositionChanged: {
                  console.log("red position changed");
              }
          }
      
          Rectangle{
              anchors.centerIn: parent
              width: 100
              height: 100
              color: "green"
              MouseArea{
                  anchors.fill: parent
                  propagateComposedEvents: true
                  onPressed: {
                      mouse.accepted = false;
                      console.log("green pressed");
                  }
                  onReleased: {
                      console.log("green released");
                  }
                  onCanceled: {
                      console.log("green canceled");
                  }
                  onPositionChanged: {
                      console.log("green position changed");
                  }
              }
          }
      }
      

      }

      @

      I click on the green rectangle, this code would produce log:

      green pressed
      green cancled
      red pressed
      red released

      At the moment I do not have idea if this is a bug or not, and how to make overlapped mouseareas to process same event.

      1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators last edited by

        Hi,

        bq. If in onPressed() handler I set accepted to false this cause Canceled signal to be generated ! If we would follow documentation this must just propagate mouse event to another MouseArea

        It will not as "propagateComposedEvents":http://doc.qt.io/qt-5/qml-qtquick-mousearea.html#propagateComposedEvents-prop only works for composed events and pressed is not a composed event.

        From the Doc:

        bq. MouseArea contains several composed events: clicked, doubleClicked and pressAndHold. These are composed of basic mouse events, like pressed, and can be propagated differently in comparison to basic events.

        157

        1 Reply Last reply Reply Quote 0
        • First post
          Last post