QtQuick ListView.indexAt() and GridView.indexAt() do not return the right item if the view has been scrolled
-
wrote on 25 Oct 2013, 10:48 last edited by
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?
-
wrote on 25 Oct 2013, 13:28 last edited by
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.
-
wrote on 27 Oct 2013, 10:36 last edited by
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"
}}
@ -
wrote on 28 Oct 2013, 07:43 last edited by
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.
-
wrote on 1 Nov 2013, 23:37 last edited by
Thanks a lot :) Work perfectly :))
2/5