Hi all,
I have a ListView which has some items inside. What I want is when the user clicked on items, the MouseArea in items can be triggered first. (since the items appear upper layer than ListView, I think it's resonable that we expect item's MouseArea receive mouse event first.) However, my experiment shows that MouseArea in ListViews receive mouse event first. Even I tried to set z value, ListViews always has higher priority to receive mouse event.
Does anyone who knows how I can make MouseArea in items to receive mouse event first?
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
ApplicationWindow {
title: qsTr("Hello World")
width: 1280
height: 720
visible: true
ListView{
id: thisListView
width: parent.width; height: parent.height
delegate: thisDelegate
model: thisListModel
spacing: 2
z:0
MouseArea{
z:0
anchors.fill: parent
propagateComposedEvents: true
onClicked: {
console.log("ListView is clicked")
mouse.accepted = false
}
}
}
ListModel{
id: thisListModel
ListElement{itemText: "1"}
ListElement{itemText: "2"}
ListElement{itemText: "3"}
}
Component{
id: thisDelegate
Rectangle{
width: thisListView.width; height: 30;
color: "lightBlue"
z: 1
Text{text: itemText; anchors.centerIn: parent}
MouseArea{
z:1
anchors.fill: parent
onClicked: {
console.log("Item is clicked")
}
}
}
}
}
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
ApplicationWindow {
title: qsTr("Hello World")
width: 1280
height: 720
visible: true
ListView{
id: thisListView
width: parent.width; height: parent.height
delegate: thisDelegate
model: thisListModel
spacing: 2
z:0
MouseArea{
z:0
anchors.fill: parent
propagateComposedEvents: true
onClicked: {
console.log("ListView is clicked")
mouse.accepted = false
}
}
}
ListModel{
id: thisListModel
ListElement{itemText: "1"}
ListElement{itemText: "2"}
ListElement{itemText: "3"}
}
Component{
id: thisDelegate
Rectangle{
width: thisListView.width; height: 30;
color: "lightBlue"
z: 1
Text{text: itemText; anchors.centerIn: parent}
MouseArea{
z:1
anchors.fill: parent
onClicked: {
console.log("Item is clicked")
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks