Set currentIndex after the model change is completed
When setting the model, the list view will first emit the countChanged signal, then will change the currentIndex to 0 (see QtDeclarative git commit 22c6873 and https://bugreports.qt.io/browse/QTBUG-26604), and finally will emit the modelChanged signal.
If we set the currentIndex in the onCountChanged handler (as we were doing
before), the currentIndex would be reset to 0 shortly afterwards.
For some mysterious reason, the desired delegate was anyway shown until the bugfix for bug 1433442 was introduced; with that bugfix, the listview is more consistent and shows the delegate corresponding to the currentIndex. Fixes: #1433442
commitcb700add19164ebc419511c13e36ecc1c4d766bb
authorAlberto Mardegan <alberto.mardegan@canonical.com>
dateMon 17 Aug 2015, 11:57 (11 years ago)
parent6b67e03c7add69
qml/Dash/PreviewListView.qml+2−2
@@ -86,10 +86,10 @@ Item {
8686 }
8787 }
8888
89− onCountChanged: {
89+ onModelChanged: {
9090 if (count > 0 && initialIndex >= 0 && !usedInitialIndex) {
9191 usedInitialIndex = true;
92− currentIndex = initialIndex;
92+ previewListView.positionViewAtIndex(initialIndex, ListView.SnapPosition);
9393 }
9494 }
9595