From 608abab51157ead5332f755b933552c8fa7899d5 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). Fixes: QTBUG-103898 Change-Id: I032c27e2788ec7e652a830383d8400b06b57d8cb Reviewed-by: David Faure (cherry picked from commit 690184cf25902e5351189c37ef823a97aaf8135a) Reviewed-by: Qt Cherry-pick Bot --- 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 c9481e892f..4b158abcdb 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -886,8 +886,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; @@ -941,7 +942,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); }