Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.9.0 Beta 4
-
None
-
95f6dcbae17b72c8dfebc9f97c77310151b63ceb
Description
A ListView does not retain its currentIndex when moving objects in an ObjectModel. This is because QQmlObjectModel::move() creates a QQmlChangeSet with moveId -1 and therefore QQmlChangeSet::isMove() returns false. QQuickItemView does not see these changes as moves, but as removals and insertions, so the current index does not follow as it should.
Steps to reproduce:
- double click any item in the list
- the item moves to the next position in the list
Expected result:
- the current index follows
Actual result:
- the current index leaves behind
import QtQuick 2.7 import QtQuick.Window 2.2 import QtQml.Models 2.2 Window { id: window width: 360 height: 360 visible: true ListView { id: listview anchors.fill: parent model: ObjectModel { id: objectmodel MouseArea { width: listview.width; height: 20 Rectangle { anchors.fill: parent; color: "lightcoral"; border.width: parent.ListView.isCurrentItem } onClicked: listview.currentIndex = ObjectModel.index onDoubleClicked: objectmodel.move(ObjectModel.index, (ObjectModel.index + 1) % 3) } MouseArea { width: listview.width; height: 20 Rectangle { anchors.fill: parent; color: "lightsteelblue"; border.width: parent.ListView.isCurrentItem } onClicked: listview.currentIndex = ObjectModel.index onDoubleClicked: objectmodel.move(ObjectModel.index, (ObjectModel.index + 1) % 3) } MouseArea { width: listview.width; height: 20 Rectangle { anchors.fill: parent; color: "lightgreen"; border.width: parent.ListView.isCurrentItem } onClicked: listview.currentIndex = ObjectModel.index onDoubleClicked: objectmodel.move(ObjectModel.index, (ObjectModel.index + 1) % 3) } } } }