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

ListView.highlightRangeMode doesn't work correctly, when ListView resizes

    XMLWordPrintable

Details

    • Linux/X11, Windows

    Description

      import QtQuick 2.12
      import QtQuick.Controls 2.5
      
      Item {
          id: root
          width: 600
          height: 600
      
          Row {
              spacing: 10
              Button {
                  text: "<"
                  font.pixelSize: 50
                  onClicked: lv.decrementCurrentIndex()
              }
              Button {
                  text: "Resize"
                  font.pixelSize: 50
                  onClicked: {
                      if (lv.anchors.margins == 200)
                          lv.anchors.margins = 0
                      else
                          lv.anchors.margins = 200
                  }
              }
              Button {
                  text: lv.currentIndex
                  font.pixelSize: 50
                  onClicked: {
                      lv.positionViewAtIndex(lv.currentIndex, ListView.SnapPosition)
                  }
              }
              Button {
                  text: ">"
                  font.pixelSize: 50
                  onClicked: lv.currentIndex += 1
              }
          }
      
          ListView {
              id: lv
              height: 100
              spacing: 20
              model: 20
              currentIndex: 10
              clip: true
              anchors.verticalCenter: root.verticalCenter
              anchors.left: root.left
              anchors.right: root.right
      
              preferredHighlightBegin: width / 2 - 50
              preferredHighlightEnd: preferredHighlightBegin + 100
              highlightRangeMode: ListView.StrictlyEnforceRange
              orientation: Qt.Horizontal
              delegate: Rectangle {
                  color: "green"
                  width: 100
                  height: 100
                  Text {
                      anchors.centerIn: parent
                      text: index
                      font.pixelSize: 50
                  }
              }
          }
      
          Rectangle {
              color: "red"
              opacity: 0.3
              width: 120
              height: 120
              anchors.centerIn: parent
          }
      }
      

      On start the currentIndex is equal to 10 and the 10th item is central.
      Steps:
      1. Click on "<" button (change currentIndex by decrementCurrentIndex/incrementCurrentIndex function) or ">" button (set currentIndex to new value)
      2. Click on "Resize" button (change ListView size)
      *Result: *
      1. The currentIndex is equal to 9/11 and the 9th/11th item is central.
      2. The current item is not central.

      If currentIndex changed by swiping or by positionViewAtIndex function, then resize works fine. The same behavior is observed for a vertical orientation.

      Attachments

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

        Activity

          People

            smd Jan Arve
            evgeniy_kolchin Kolchin Evgeny
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes