Problems with Open-Source Downloads read and

QT QUICK - How to detect click out of mouse area?

  • I am a little new to QT Quick and i know there is element called MouseArea to detect key pressed or mouse activity inside a rectangular region. My question is how do you detect mouse clicks outside a mouseArea?

    Thanks in advanced

  • Moderators


    In simple words you will need another MouseArea.
    Now consider this example:
    import QtQuick 2.0

    Item {
    id: outerRect
    width: 300
    height: 300

    MouseArea {
        anchors.fill: parent
        onClicked: console.log("Outer Clicked")
    Rectangle {
        id: innerRect
        width: 50
        height: 50
        color: "red"
        MouseArea {
            anchors.fill: parent
            onClicked: console.log("Inner Clicked")


    In above example the outerRect acts as a container for the innerRect. Now if i get you correctly you are clicking the innerRect's MouseArea for the mouse activity. If you want to handle clicks outside it you will need another MouseArea which here is defined for outerArea.
    Try running the above example.
    I'd suggest you to read "MouseArea": docs.
    Hope this helps you.

  • Thanks for the tip

Log in to reply