Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-11405

Setting ListView's currentIndex interfears with ongoing flick scolling

    XMLWordPrintable

Details

    • c09f58965e772064ca952892f2e7969082f03855

    Description

      Run the code below and flick the list. Note that when the current item (pink)
      reach the boundary of the list, the flick abruptly stops because of currentIndex
      being set in the onContentYChanged implementation.

      import Qt 4.7
      
      ListView {
          id: listView
          width: 320; height: 480;
          snapMode: ListView.SnapToItem
      
          onContentYChanged: {    // keep "current" item visible
              var topIndex = indexAt(0,contentY);
              var bottomIndex = indexAt(0, contentY+height);
      
              if(topIndex != -1 && currentIndex <= topIndex)
                  currentIndex = topIndex+1;
              else if(bottomIndex != -1 && currentIndex >= bottomIndex)
                  currentIndex = bottomIndex-1;
          }
      
          model: 50
          delegate: Rectangle {
              width: 320
              height: 40
              color: {
                  if(ListView.isCurrentItem)
                      return focus ? "red" : "pink";
      
                  return index % 2 == 0 ? "lightblue" : "blue"
              }
              Text { anchors.centerIn: parent; text: index }
      
              MouseArea {
                  anchors.fill: parent
                  onClicked: listView.currentIndex = index
              }
          }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            martjone Martin Jones (closed Nokia identity) (Inactive)
            mathiasm Mathias Malmqvist
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes