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. Why onCurrentIndexChanged in ListView isn't executed?

Why onCurrentIndexChanged in ListView isn't executed?

Scheduled Pinned Locked Moved QML and Qt Quick
listviewqml
2 Posts 1 Posters 1.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.
  • N Offline
    N Offline
    niez
    wrote on last edited by niez
    #1

    Why onCurrentIndexChanged is called only once at startup? When I change 'page' then currentIndex doesn't change. Here is my code:

        ApplicationWindow
        {
            visible: true
    
            ListView
            {
                anchors.fill: parent
    
                orientation: ListView.Horizontal
                snapMode: ListView.SnapOneItem
    
                onCurrentIndexChanged: console.log("currentIndex changed: " + currentIndex)
    
                model: 10
    
                delegate: Rectangle
                {
                    width: ListView.view.width
                    height: ListView.view.height
    
                    color: "#ffffffff";
                    border.color: "#ff000000";
    
                    Text
                    {
                        anchors.centerIn: parent
                        text: index
                    }
                }
            }
        }
    
    N 1 Reply Last reply
    0
    • N niez

      Why onCurrentIndexChanged is called only once at startup? When I change 'page' then currentIndex doesn't change. Here is my code:

          ApplicationWindow
          {
              visible: true
      
              ListView
              {
                  anchors.fill: parent
      
                  orientation: ListView.Horizontal
                  snapMode: ListView.SnapOneItem
      
                  onCurrentIndexChanged: console.log("currentIndex changed: " + currentIndex)
      
                  model: 10
      
                  delegate: Rectangle
                  {
                      width: ListView.view.width
                      height: ListView.view.height
      
                      color: "#ffffffff";
                      border.color: "#ff000000";
      
                      Text
                      {
                          anchors.centerIn: parent
                          text: index
                      }
                  }
              }
          }
      
      N Offline
      N Offline
      niez
      wrote on last edited by
      #2

      Ok, solution found. currentIndex/onCurrentIndexChanged is useless in this scenario. Here is updated code:

      ApplicationWindow
      {
          visible: true
      
          ListView
          {
              anchors.fill: parent
      
              orientation: ListView.Horizontal
              snapMode: ListView.SnapOneItem
      
              model: 10
      
              onMovementEnded: console.log("current item changed: " + itemAt(contentX,contentY).itemIndex)
      
              delegate: Rectangle
              {
                  property int itemIndex: index
      
                  width: ListView.view.width
                  height: ListView.view.height
      
                  color: "#ffffffff";
                  border.color: "#ff000000";
      
                  Text
                  {
                      anchors.centerIn: parent
                      text: index
                  }
              }
          }
      }
      
      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