summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2023-03-25 19:11:13 +0100
committerAxel Spoerl <axel.spoerl@qt.io>2023-03-31 13:09:39 +0200
commita815c40e736d0914b898a896f3dcee454804a7a2 (patch)
tree7b2f537f013ba72a9db3ed92c0abf87d871dfbff /src/widgets/itemviews
parenta94ba94695fe20d0cddc9b33396262ba3ed2b07f (diff)
QListView: No-op, when a list item is dropped directly behind itself
QListView generates a move, when an item is dropped directly behind itself. This causes unexpected behavior, e.g. item widgets getting discarded. This patch prevents a move from being generated in that case. It adds an autotest to tst_QWidget, to verify item widgets and item data do not get discarded in case of a no-op drag&drop. Fixes: QTBUG-100128 Pick-to: 6.5 6.2 Change-Id: I02a755320a7b71dad218293c9c94c88da6507423 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qlistview.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index b03c1a47f5..2513bb2a0c 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -910,7 +910,8 @@ void QListView::dropEvent(QDropEvent *event)
bool dataMoved = false;
for (int i = 0; i < persIndexes.size(); ++i) {
const QPersistentModelIndex &pIndex = persIndexes.at(i);
- if (r != pIndex.row()) {
+ // only generate a move when not same row or behind itself
+ if (r != pIndex.row() && r != pIndex.row() + 1) {
// try to move (preserves selection)
dataMoved |= model()->moveRow(QModelIndex(), pIndex.row(), QModelIndex(), r);
if (!dataMoved) // can't move - abort and let QAbstractItemView handle this