diff options
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qlistwidget.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index ca7439b08c..f04cfe45d9 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -373,7 +373,7 @@ void QListModel::ensureSorted(int column, Qt::SortOrder order, int start, int en if (column != 0) return; - int count = end - start + 1; + const int count = end - start + 1; QList<QPair<QListWidgetItem *, int>> sorting(count); for (int i = 0; i < count; ++i) { sorting[i].first = items.at(start + i); @@ -399,7 +399,12 @@ void QListModel::ensureSorted(int column, Qt::SortOrder order, int start, int en int newRow = qMax<qsizetype>(lit - tmp.begin(), 0); lit = tmp.insert(lit, item); if (newRow != oldRow) { - changed = true; + if (!changed) { + emit layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint); + oldPersistentIndexes = persistentIndexList(); + newPersistentIndexes = oldPersistentIndexes; + changed = true; + } for (int j = i + 1; j < count; ++j) { int otherRow = sorting.at(j).second; if (oldRow < otherRow && newRow >= otherRow) @@ -425,10 +430,9 @@ void QListModel::ensureSorted(int column, Qt::SortOrder order, int start, int en } if (changed) { - emit layoutAboutToBeChanged(); items = tmp; changePersistentIndexList(oldPersistentIndexes, newPersistentIndexes); - emit layoutChanged(); + emit layoutChanged({}, QAbstractItemModel::VerticalSortHint); } } |