QML Listview onClick event(solved)
-
wrote on 27 Mar 2014, 10:05 last edited by
Hi all,
I have used itemAt(mouseX, mouseY) for getting the clicked buttons inside QML listview. It works fine, but when i scroll the listView to bottom and tried to click the bottom or other buttons it is not getting selected. It is taking only the area inside its parent window.
How can i solve this issue ?Ansif
-
wrote on 27 Mar 2014, 10:34 last edited by
You need to take into account ListView::originX, ListView::originY, ListView::contentX and ListView::contentY.
ListView (and Flickable) are only showing a part of the whole content. When you scroll the "move" their content to the right position. So you need to convert the coordinates you get from your MouseArea to the coordinates of the content in the ListView.
-
wrote on 27 Mar 2014, 13:43 last edited by
there might be a better solution, I don't know exactly what you want to achieve but I guess you just want a click event for all items in the ListView?
Why don't you use a MouseArea inside the delegate, so every item has its own MouseArea and no need to use itemAt with some "weird" calculations. :p
-
wrote on 27 Mar 2014, 14:50 last edited by
[quote author="t3685" date="1395916442"]You need to take into account ListView::originX, ListView::originY, ListView::contentX and ListView::contentY.
ListView (and Flickable) are only showing a part of the whole content. When you scroll the "move" their content to the right position. So you need to convert the coordinates you get from your MouseArea to the coordinates of the content in the ListView.
[/quote]Hi,
Yes it works, thank you. I have used the contentY property and it is using the exact location.
Thank you -
wrote on 27 Mar 2014, 14:53 last edited by
[quote author="Xander84" date="1395927825"]there might be a better solution, I don't know exactly what you want to achieve but I guess you just want a click event for all items in the ListView?
Wy don't you use a MouseArea inside the delegate, so every item has its own MouseArea and no need to use itemAt with some "weird" calculations. :p[/quote]
I never used this behaviour. hence my problem is fixed
-
wrote on 27 Mar 2014, 19:03 last edited by
Don't forget to take into account originX and originY as well.
-
wrote on 27 Mar 2014, 19:04 last edited by
[quote author="t3685" date="1395946982"]Don't forget to take into account originX and originY as well. [/quote]
There is no need for that if you use a MouseArea in the delegate or what do you mean!?
5/7