Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Bug ? MouseEvent generates Canceled signal if not accepted



  • 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.


  • Moderators

    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.


Log in to reply