How retrieve the position in a ListView from a ListView
-
Hello everybody,
I make a ListView in a listView like :
ListView{ id: id_a orientation: ListView.Vertical verticalLayoutDirection: ListView.TopToBottom model : a delegate : Item{ ListView{ id : id_b orientation: ListView.Horizontal layoutDirection: ListView.RightToLeft model : b delegate : Rectangle{ width: 10 height: 10 MouseArea{ anchors.fill:parent onClicked: { console.log("y : " + A.length + " x : " + B.length ) console.log("y : " + id_a.currentItem + " x : " + id_b.currentItem ) console.log("y : " + id_a.count + " x : " + id_b.count ) } } } } } }
I show you only the information important in my example. As you can see I would like to know the position where I clicked, but the console return always the same thing except for the currentItem which change:
qml: y : 150 x : 320
qml: y : QQuickItem(0x558c5a7f64c0) x : QQuickRectangle(0x558c5c9b1220)
qml: y : 150 x : 320do you have an idea to how can I retrieve the position where I click ?
thanks -
Hello everybody,
I make a ListView in a listView like :
ListView{ id: id_a orientation: ListView.Vertical verticalLayoutDirection: ListView.TopToBottom model : a delegate : Item{ ListView{ id : id_b orientation: ListView.Horizontal layoutDirection: ListView.RightToLeft model : b delegate : Rectangle{ width: 10 height: 10 MouseArea{ anchors.fill:parent onClicked: { console.log("y : " + A.length + " x : " + B.length ) console.log("y : " + id_a.currentItem + " x : " + id_b.currentItem ) console.log("y : " + id_a.count + " x : " + id_b.count ) } } } } } }
I show you only the information important in my example. As you can see I would like to know the position where I clicked, but the console return always the same thing except for the currentItem which change:
qml: y : 150 x : 320
qml: y : QQuickItem(0x558c5a7f64c0) x : QQuickRectangle(0x558c5c9b1220)
qml: y : 150 x : 320do you have an idea to how can I retrieve the position where I click ?
thanks@cosmoff said in How retrieve the position in a ListView from a ListView:
do you have an idea to how can I retrieve the position where I click ?
onClicked: { console.log("y : " + mouse.y + " x : " + mouse.x ) }
-
@cosmoff said in How retrieve the position in a ListView from a ListView:
do you have an idea to how can I retrieve the position where I click ?
onClicked: { console.log("y : " + mouse.y + " x : " + mouse.x ) }
-
You can use
itemAt()
function for that purpose. For your parent item you'd have to map the coordinates. -
You can access the index of a delegate using the
index
context property (ormodel.index
) :ListView{ id: id_a orientation: ListView.Vertical verticalLayoutDirection: ListView.TopToBottom model : a delegate : Item{ ListView{ id : id_b readonly property int rowIndex: index orientation: ListView.Horizontal layoutDirection: ListView.RightToLeft model : b delegate : Rectangle{ width: 10 height: 10 MouseArea{ anchors.fill:parent onClicked: { console.log("row", id_b.rowIndex, "column", index) } } } } } }
-
You can access the index of a delegate using the
index
context property (ormodel.index
) :ListView{ id: id_a orientation: ListView.Vertical verticalLayoutDirection: ListView.TopToBottom model : a delegate : Item{ ListView{ id : id_b readonly property int rowIndex: index orientation: ListView.Horizontal layoutDirection: ListView.RightToLeft model : b delegate : Rectangle{ width: 10 height: 10 MouseArea{ anchors.fill:parent onClicked: { console.log("row", id_b.rowIndex, "column", index) } } } } } }