-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.7.2
-
None
-
58ae252e5555dc379b4ed500532bc51ff7bebc25
Run the code below. Move the blue highlight with the up and down arrow keys.
Press Enter to make the blue highlighted item the "current" one (shown with red text).
Note that the green highlightItem is explicitly position one item below the "current" item.
Move the blue highlight one item up or down, and note how the green highlightItem
moves automatically to the Y-position of the currentItem, despite that the ListView's
highlightFollowsCurrentItem has been set to false. If the positionViewAtIndex() call is
commented out the highlightItem doesn't move, but the blue highlight doesn't stay in
view as it should.
import Qt 4.7 Rectangle { width: 800 height: 640 Rectangle { width: 200 height: 400 anchors.centerIn: parent color: "yellow" ListView { id: listView anchors.fill: parent interactive: false clip: true highlightFollowsCurrentItem: false property int highlightedIndex: 0 onHighlightedIndexChanged: { //BUG! Calling positionViewAtIndex() results in highlightItem is moved // despite highlightFollowsCurrentItem == false positionViewAtIndex(highlightedIndex, ListView.Contain) } onCurrentIndexChanged: { // position the highlight with 20px offset highlightItem.x = currentItem.x+20 highlightItem.y = currentItem.y+20 highlightItem.width = currentItem.width highlightItem.height = currentItem.height } model: 50 highlight: Rectangle { color: "green" } delegate: Rectangle { id: delegateItem height: 20 width: 200 color: index == listView.highlightedIndex ? "blue" : "transparent" Text { anchors.centerIn: parent color: index == ListView.view.currentIndex ? "red" : "black" text: "Item number " + index } } focus: true Keys.onPressed: { if (event.key == Qt.Key_Up ) { if(highlightedIndex > 0) highlightedIndex--; } else if (event.key == Qt.Key_Down ) { if(highlightedIndex+1 < listView.count) highlightedIndex++; } else if (event.key == Qt.Key_Enter || event.key == Qt.Key_Return) { listView.currentIndex = highlightedIndex; } } } } }