QML Listview onClick event(solved)



  • 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



  • 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.



  • 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



  • [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



  • [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



  • Don't forget to take into account originX and originY as well.



  • [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!?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.