Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QtQuick ListView.indexAt() and GridView.indexAt() do not return the right item if the view has been scrolled
Forum Updated to NodeBB v4.3 + New Features

QtQuick ListView.indexAt() and GridView.indexAt() do not return the right item if the view has been scrolled

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    braders2
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gennon
      wrote on last edited by
      #2

      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.

      /Gen

      1 Reply Last reply
      0
      • B Offline
        B Offline
        braders2
        wrote on last edited by
        #3

        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
        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"
        }

        }
        @

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Gennon
          wrote on last edited by
          #4

          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.

          /Gen

          1 Reply Last reply
          0
          • B Offline
            B Offline
            braders2
            wrote on last edited by
            #5

            Thanks a lot :) Work perfectly :))

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved