Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ListView is not showing currentIndex
Forum Updated to NodeBB v4.3 + New Features

ListView is not showing currentIndex

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 217 Views
  • 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.
  • M Offline
    M Offline
    Mihaill
    wrote on last edited by
    #1

    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
            }
    
    ODБOïO 2 Replies Last reply
    0
    • M Mihaill

      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
              }
      
      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @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
              }
          }
       }
      
      1 Reply Last reply
      1
      • M Mihaill

        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
                }
        
        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        @Mihaill np

        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