From 690184cf25902e5351189c37ef823a97aaf8135a Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 2 Oct 2024 14:10:16 +0200 Subject: [PATCH] QListView: don't ignore an event accepted by a subclass If a subclass reimplements dropEvent() to accept a CopyAction, then don't ignore the event again in the QListView implementation. We only have to ignore a MoveAction event if the handling so far didn't actually move the data, so that the QAIV implementation can handle the removal of the source data if needed. Complex interaction between QListView and QAbstractItemView, especially in IconView mode, and sadly not generally unit-testable, like all drag'n'drop interactions (due to modally blocking QDrag::exec on most platforms). Pick-to: 6.8 Fixes: QTBUG-103898 Change-Id: I032c27e2788ec7e652a830383d8400b06b57d8cb Reviewed-by: David Faure --- src/widgets/itemviews/qlistview.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 9be17387618..3d615f84f5e 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -883,8 +883,9 @@ void QListView::dropEvent(QDropEvent *event) { Q_D(QListView); - if (event->source() == this && (event->dropAction() == Qt::MoveAction || - dragDropMode() == QAbstractItemView::InternalMove)) { + const bool moveAction = event->dropAction() == Qt::MoveAction + || dragDropMode() == QAbstractItemView::InternalMove; + if (event->source() == this && moveAction) { QModelIndex topIndex; bool topIndexDropped = false; int col = -1; @@ -937,7 +938,7 @@ void QListView::dropEvent(QDropEvent *event) if (!d->commonListView->filterDropEvent(event) || !d->dropEventMoved) { // icon view didn't move the data, and moveRows not implemented, so fall back to default - if (!d->dropEventMoved) + if (!d->dropEventMoved && moveAction) event->ignore(); QAbstractItemView::dropEvent(event); }