QtQuick ListView.indexAt() and GridView.indexAt() do not return the right item if the view has been scrolled
-
Hi i have problem with ListView.Indexat(). When i scrolled do not return right item. In this website is solution https://bugreports.qt-project.org/browse/QTBUG-16672 fix my problem but I don't know how to install this patch.diff. Can u give me steps how to install this patch?
-
Make use of the contentY property.
http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-flickable.html#contentY-prop
Then you can calculate correct y and use it into the indexAt function.
-
I dont know how propely use contentY. Can u help me?
This is my code
@import QtQuick 1.0
import QtQuick 1.1Item {
id: parentrect
width: 800
height: 350
Image{
source: "tlo3.jpg"
}Rectangle { id: menu x:10 y:20 width: 200 height : 505 radius: 10 color : "#e1ddcf" Rectangle { y:20 color : "#e1ddcf" width: 180; height: 200 Component { id: contactDelegate Item { width: 180; height: 38 x:30 Image { id:pic; source: *****} Text {anchors.left: pic.right; anchors.leftMargin: 10;text: '<b>'+name+'</b>' } } } } ListView { id: listview1 anchors.margins: 7 anchors.fill: parent model: Menu {} delegate: contactDelegate highlight: Rectangle { color: "lightsteelblue"; radius: 5 } MouseArea { anchors.fill: parent hoverEnabled: true onPositionChanged: { listview1.currentIndex = listview1.indexAt(mouseX, mouseY) //here use flickable.contentY? } } focus: true }
}
Rectangle{
x:10
y:520
id:kurosry
width:200
height: 20
color: "black"
}}
@ -
Can I ask you what you want to achieve?
It looks like you want to set focus to the item that your mouse is hoovering over? Is that true? If that is the case then you should just use a MouseArea in the ListView delegate instead. And you could set some other color or whatever when the mouse is hoovering over the item right in the delegate. No need to use the index.
-
Thanks a lot :) Work perfectly :))