How to include child mouse hover events in the parent MouseArea using QML?

前端 未结 4 1970
自闭症患者
自闭症患者 2021-02-02 09:20

I want to implement the following scenario in QML.

\"Scenario\"


Here is a sample/simplified delegat

4条回答
  •  Happy的楠姐
    2021-02-02 09:52

    I was faced by this same problem, and came across the answer in the QtQuick 5.0 documentation for MouseArea. The answer to this is actually quite simple.

    If you want to include child mouse hover events in your parent MouseArea, make you child MouseArea a child of the parent MouseArea:

    MouseArea {
        id: parent
    
        MouseArea {
            id: child
        }
    }
    

    Since I have a custom Widget type that would be used as the parent view, I ended up with the default property being the children of the MouseArea:

    Item {
        default property alias children: mouseArea.data
    
        MouseArea {
            id: mouseArea
        }
    }
    

提交回复
热议问题