Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Not work when Flow and MouseArea in a ScrollView
Forum Update on Monday, May 27th 2025

Not work when Flow and MouseArea in a ScrollView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 179 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kacapeng
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved