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

MouseArea behind another control



  • I have a scenario where I have a MouseArea that I am covering with another control. The issue is that it doesn't disable the clicked event. You can just click "through" the covering control. Is there any way to fix this? Is there a way in the onClicked to tell if the MouseArea is visible? Here is an example.

    import QtQuick 2.9
    import QtQuick.Controls 2.2
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle {
            color: "red"
            anchors.fill: parent
            MouseArea {
                anchors.left: parent.left
                anchors.top: parent.top
                width: 100
                height: 100
                onClicked: console.debug("clicked")
    
            }
        }
        Rectangle {
            color: "blue"
            anchors.fill: parent
    
        }
    }
    


  • @krobinson
    You can simply intercept and ignore the mouse events inside the blue rectangle:

        Rectangle {
            color: "blue"
            anchors.fill: parent
            MouseArea {
                anchors.fill: parent
            }
        }
    

Log in to reply