Scrolling of ListView when changing currentItem
-
Hi,
I have a ListView of many items and I like to keep the selected item always visible and keep also one above the selected and one below the selected. This can be done using preferredHighlightBegin and preferredHighlightEnd. It seems to work fine but there is a strange behavior when selecting items which are distant from each other.
For example let's say I select item #2 then I scroll down and select item #15 which is at the bottom of the view. What I would expect is that the ListView will move a little up so the item becomes not last visible but 2. from bottom. What in fact happens is that the ListView immediately displays item #2 and then scrolls down to item #15.
How do I avoid this strange behavior? The only thing I could come up is to set the ListView currentIndex first to -1 and then to the desired index. But this causes that the ListView will directly skip to desired position, not scroll smoothly.
Unfortunately my English is not perfect and I'm not sure if I could explain the problem correctly. So I created this sample. Just save it as a QML file and open it in the viewer. Then try to select distant items.
@import QtQuick 1.0
Rectangle {
width: 200
height: 200
color: "#333333"ListModel { id: listModel }
Component {
id: listDelegateItem { anchors.right: parent.right anchors.left: parent.left height: 50 Rectangle { id: frame anchors.fill: parent anchors.rightMargin: 5 anchors.leftMargin: 5 anchors.topMargin: 5 anchors.bottomMargin: 5 color: "#00000000" radius: parent.height/4 border.width: 2 border.color: listView.currentIndex == index ? "#ffff00" : "#ffffff" MouseArea { id: itemMouseArea anchors.fill: parent anchors.rightMargin: 0 onClicked: { listView.currentIndex = index } } Text { id: text color: "#ffffff" text: itemText anchors.centerIn: parent font.pointSize: 20 } } }
}
ListView { id: listView clip: true anchors.fill: parent model: listModel delegate: listDelegate preferredHighlightEnd: 150 preferredHighlightBegin: 50 highlightRangeMode: ListView.ApplyRange } Component.onCompleted: { for (var i = 0; i < 21; i++) { listModel.append({"itemText": "Item #"+i}) } }
}@
-
You tryed to use
@followCurrentItem: true@ -
AFAIK ListView has no property followCurrentItem, it only has highlightFollowsCurrentItem, which doesn't make any difference.
-
Bump!
Could anyone at least please confirm, if this is intended behavior or a bug in Qt?
I'm sorry for my impatience, but I would like to make a release of my program and this is blocking me from doing it.