Important: Please read the Qt Code of Conduct -

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

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

    Item {
    id: parentrect
    width: 800
    height: 350
    source: "tlo3.jpg"

    Rectangle {
        id: menu
        width: 200
        height : 505
        radius: 10
        color : "#e1ddcf"
            Rectangle  {
            color : "#e1ddcf"
            width: 180; height: 200
            Component  {
                id: contactDelegate
                Item  {
                    width: 180; height: 38
                    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

    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 :))

Log in to reply