我在另一个有
TableView
的 Item
中有 MouseArea
。如何将所有鼠标事件传递给 TableView
的父级(或者换句话说,使其对鼠标事件透明)?
如果只想获取父项中的鼠标事件,请将鼠标区域堆叠在表格上方。
使用
propagateComposedEvents
你可以实现,两者都获取鼠标事件。
小例子:
Rectangle {
color: "red"
anchors.fill: parent
Rectangle {
color: "green"
anchors.fill: parent
anchors.margins: 20
MouseArea {
anchors.fill: parent
onClicked: console.log("green")
}
}
MouseArea {
anchors.fill: parent
// if you activate this, both mouse areas get the click
propagateComposedEvents: true
onClicked: (mouse) => {
// true: only one mouse area is getting the event if propagateComposedEvents is set
// false: both mouse areas are getting the event if propagateComposedEvents is set
mouse.accepted = false;
console.log("red")
}
}
}