Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

ListView is not showing currentIndex



  • Hi!
    When scrolling, the listView does not show the currentIndex. currentIndex is always 0. How to get correct currentIndex?

        ListView{
            id: listView1
            anchors.bottom: rectangleDown.top
            anchors.bottomMargin: 15
            anchors.top: rectangleTop.bottom
            anchors.topMargin: 0
            anchors.right: rectangleTop.right
            anchors.rightMargin: 0
            anchors.left: rectangleTop.left
            anchors.leftMargin: 0
            clip: true
            snapMode: ListView.SnapToItem
    
            model: ListModel
            {
                id: listModel1
            }
    


  • @mihaill said in ListView is not showing currentIndex:

    the listView does not show the currentIndex

    the listView must show what you define in the delegate property

     ListView{
         id:l
        anchors.fill: parent
        model: ["data 1","data 2","data 3"]
        currentIndex : 2
        delegate: Text {
            Rectangle{
                color: index === l.currentIndex ? "green" : "red"
                height: 30
                width: 20
            }
            id: name
            text :"DATA : "  + modelData +  " index is : " + index + "; Listview currentindex is " +  l.currentIndex
            height: 100
            MouseArea{
                anchors.fill: parent
                onClicked: l.currentIndex  = index
            }
        }
     }
    



Log in to reply