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

Flicking a ListView makes it loose focus

    XMLWordPrintable

Details

    • 7a577ff67388413a882435c5cbd1ad6d1fa8393d

    Description

      Run the code below. The "current" item list should be drawn in red if the list has focus,
      or pink if the list does not have focus. Flick one of the lists and note how the highlight
      changes between red and pink. The same applies when using the arrow keys.

      Uncomment the onMasterIndexChanged implementation and note how the defect
      mention above interferes with the flicking animation and prevents the lists from staying
      in perfect sync.

      import Qt 4.7
      
      Rectangle {
          width: 640; height: 480;
      
          property int masterIndex: 0
      /*
          onMasterIndexChanged: {
              if(listViewOne.focus == false) {
                  listViewOne.positionViewAtIndex(masterIndex, ListView.Visible);
                  listViewOne.currentIndex = masterIndex;
              }
              if(listViewTwo.focus == false) {
                  listViewTwo.positionViewAtIndex(masterIndex, ListView.Visible);
                  listViewTwo.currentIndex = masterIndex;
              }
          }
      */
          ListView {
              id: listViewOne
              anchors.top: parent.top
              anchors.bottom: parent.bottom
              anchors.left: parent.left
              anchors.right: parent.horizontalCenter
      
              onCurrentIndexChanged: parent.masterIndex = currentIndex
              snapMode: ListView.SnapToItem
              highlightRangeMode: ListView.StrictlyEnforceRange
              preferredHighlightBegin: 100
              preferredHighlightEnd: 380
      
              model: 50
              delegate: Rectangle {
                  width: 320
                  height: 40
                  color: {
                      if(ListView.isCurrentItem)
                          return listViewOne.focus ? "red" : "pink";
      
                      return index % 2 == 0 ? "lightblue" : "blue"
                  }
                  Text { anchors.centerIn: parent; text: index }
      
                  MouseArea {
                      anchors.fill: parent
                      onClicked: listViewOne.currentIndex = index
                  }
              }
          }
      
      
          ListView {
              id: listViewTwo
              anchors.top: parent.top
              anchors.bottom: parent.bottom
              anchors.left: parent.horizontalCenter
              anchors.right: parent.right
      
              onCurrentIndexChanged: parent.masterIndex = currentIndex
              snapMode: ListView.SnapToItem
              highlightRangeMode: ListView.StrictlyEnforceRange   //ApplyRange
              preferredHighlightBegin: 100
              preferredHighlightEnd: 380
      
              model: 50
              delegate: Rectangle {
                  width: 320
                  height: 60
                  color: {
                      if(ListView.isCurrentItem)
                          return listViewTwo.focus ? "red" : "pink";
      
                      return index % 2 == 0 ? "lightgreen" : "green"
                  }
                  Text { anchors.centerIn: parent; text: index }
      
                  MouseArea {
                      anchors.fill: parent
                      onClicked: listViewTwo.currentIndex = index
                  }
              }
          }
      
          Rectangle { // Highlight range indicator
              width: parent.width
              y: 100
              height: 280
              color: "black";
              opacity: 0.5;
      
              Text { text: masterIndex; color: "white"; anchors.centerIn: parent; font.pixelSize: 100 }
          }
      }
      

      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