Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.7.1
-
None
-
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 } } }