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

button click goes through the items ..



  • hi,

    Can please someone help me to understand and solve this issue ?

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.12
    import QtQuick.Layouts 1.12
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        MouseArea{
            anchors.fill: parent
            onClicked: {
                console.log("main area clicked")
            }
        }
        Rectangle{  // click this rectangle will output "main area clicked"
            anchors.centerIn: parent
            height: parent.height *0.8
            width: parent.width *0.8
            color : "orange"
            RowLayout{
                anchors.fill: parent
                spacing: 30
                Button{
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    text: "clickme"
                    onClicked: {
                        console.log("btn 1 click")
                    }
                }
                Button{ // click this disabled Button will output "main area clicked"
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    text: "clickme"
                    enabled: false
                    onClicked: {
                        console.log("btn 2 click")
                    }
                }
            }
        }
    }
    

  • Moderators

    Rectangle is transparent to mouse events, so it lets your click through. Add a mouse area inside it to stop the event from propagating.

    Disabled button - same story, it's disabled so it will likely pass the event further.

    I haven't tested this, so it's a bit of a guess.


Log in to reply