Non-Blocking mouse area that could receive mouse release event


  • Qt Champions 2016

    Hi,

    I would like to make a mouse area which could receive mouse press and release event while it could propagate all the mouse event to its parent. So that It won't block any evens.

    I have tried to make a custom QQuickItem and reimplement the mousePressEvent() handler.

    void MouseSensor::mousePressEvent(QMouseEvent *event)
    {
       emit pressed(); 
       return QQuickItem::mousePressEvent(event);
    }
    

    It could receive mousePressEvent and propagate to its parent, but it won't receive mouseMouseEvent and mouseReleaseEvent. If I set accepted to true and don't call parent's mousePressEvent, then I could got the mouseReleaseEvent but it won't propagate events to parent.

    What could I do to make it propagate all the event to parent and it could receive mouseReleaseEvent?

    Thanks for any advise.



  • According the MouseArea pressed event documentation:

    "If accepted is set to false, no further events will be sent to this MouseArea until the button is next pressed."

    Because of this you can't have a release event fired if you set in onPressed the mouse.accepted to false, because the signal is sent to the parent and there its were you will get the relese event fired.
    However there's a workaround, you can tell the parent release event to fire the child release event, see the next example:

    MouseArea {
            id:area1
            anchors.fill: parent
            onPressed: {
                console.log("pressed on area1")
            }
            onReleased: {
                console.log("released on area1")
                area2.released(mouse)
            }
            MouseArea {
                id: area2
                anchors.fill: parent
    
                propagateComposedEvents: true
                onPressed: {
                    console.log("pressed on area2")
                    mouse.accepted = false
                }
                onReleased: {
                    console.log("released on area2")
                }
            }
        }
    

    You should be able to do the same for mouse move events


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.