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

Not work when Flow and MouseArea in a ScrollView



  • no MouseArea:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.0
    
    
    Window {
        id: root
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
    
        ScrollView{
            anchors.fill: parent
    
            Flow{
                width: parent.width
                Rectangle{
                    width: 300
                    height: 300
                    color: "red"
                }
                Rectangle{
                    width: 300
                    height: 300
                    color: "blue"
                }
                Rectangle{
                    width: 300
                    height: 300
                    color: "pink"
    
                    MouseArea{
                        anchors.fill: parent
                        onClicked:{
                            parent.color =  Qt.rgba(Math.random(), Math.random(), Math.random())
                        }
    
                    }
                }
    
            }
        }
    }
    
    

    9a6827a8-805a-4410-9734-50dc8d34206e-image.png

    Add a MouseArea:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.0
    
    
    Window {
        id: root
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
    
        ScrollView{
            anchors.fill: parent
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    root.color = Qt.rgba(Math.random(), Math.random(), Math.random())
                }
            }
            Flow{
                width: parent.width
                Rectangle{
                    width: 300
                    height: 300
                    color: "red"
                }
                Rectangle{
                    width: 300
                    height: 300
                    color: "blue"
                }
                Rectangle{
                    width: 300
                    height: 300
                    color: "pink"
    
                    MouseArea{
                        anchors.fill: parent
                        onClicked:{
                            parent.color =  Qt.rgba(Math.random(), Math.random(), Math.random())
                        }
    
                    }
                }
    
            }
        }
    }
    
    

    90e44361-8f55-43a2-900d-cb91e4cf75ad-image.png

    How do I let ScrollView accept mouse events?


Log in to reply