PDA

View Full Version : ListView indexAt,itemAt issue



batmanvn
29th September 2017, 05:20
I have ListView and i use mouse coordinate check and get index, item from ListView. I use listView.indexAt(x,y), listView.itemAt(x,y), in normal ListView i get them successfully but in ListView i add verticalLayoutDirection: ListView.BottomToTop, listView.indexAt(x,y), listView.itemAt(x,y) can't get value.
How i can get indexAt, itemAt correct?



ListView {
id:list
anchors.fill: parent
interactive: false
verticalLayoutDirection: ListView.BottomToTop
MouseArea {
id:mous
anchors.fill: parent
onPositionChanged: {

var positionInRoot = mapToItem(list, mouse.x, mouse.y)

var index = list.indexAt(positionInRoot.x,positionInRoot.y) // is not correct when use verticalLayoutDirection: ListView.BottomToTop
var item = list.itemAt(positionInRoot.x,positionInRoot.y) // is not correct when use verticalLayoutDirection: ListView.BottomToTop

}
}

wysota
29th September 2017, 08:46
Does using list.height-positionInRoot.y etc. yield proper indices? Why do you need that index value at all? If it is your actual code then MouseArea is the delegate for the view so it is enough to react to onEntered and onExited to store the "current" index on the view. If MouseArea is not your delegate then you can apply MouseArea to the delegate item and re-read the previous sentence of my post.