aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-06-12 10:23:56 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-15 15:44:55 +0000
commit7c70326dcd79dbe0a2a325d63b2e87698491c761 (patch)
treec091999205e6d96eb90b11113629bba33a2e3fec
parenta4646cb244963bf4b5667b53dcb25430f91dc814 (diff)
Don't deliver QDragEnterEvent to a drop area that is a child of the dragged item
If the drag.target of the mouse area that starts the drag is a parent of a drop area, then that drop area cannot be dropped on (as it's moving with the dragged item). Due to QQuickDeliveryAgentPrivate::deliverDragEvent calling itself recursively, this is the earliest place where we can block this event from being delivered. Fixes: QTBUG-64128 Change-Id: I495492161d67f7ac60eafb99982fb01ec2374c50 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit e36b5ce4df4239fdf7c54afcc9c261fe1cceafc1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quick/items/qquickdroparea.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/quick/items/qquickdroparea.cpp b/src/quick/items/qquickdroparea.cpp
index 7d3db1e7c2..21dc0979a9 100644
--- a/src/quick/items/qquickdroparea.cpp
+++ b/src/quick/items/qquickdroparea.cpp
@@ -262,6 +262,16 @@ void QQuickDropArea::dragEnterEvent(QDragEnterEvent *event)
if (!d->effectiveEnable || d->containsDrag || !mimeData || !d->hasMatchingKey(d->getKeys(mimeData)))
return;
+ const QQuickDragMimeData *dragMime = qobject_cast<const QQuickDragMimeData *>(mimeData);
+ auto dragSource = dragMime ? dragMime->source() : event->source();
+
+ // if the source of the drag is an ancestor of the drop area, then dragging
+ // also drags the drop area; see QTBUG-64128
+ if (QQuickItem *dragSourceItem = qobject_cast<QQuickItem *>(dragSource)) {
+ if (dragSourceItem->isAncestorOf(this))
+ return;
+ }
+
d->dragPosition = event->position().toPoint();
event->accept();
@@ -272,10 +282,7 @@ void QQuickDropArea::dragEnterEvent(QDragEnterEvent *event)
return;
d->containsDrag = true;
- if (QQuickDragMimeData *dragMime = qobject_cast<QQuickDragMimeData *>(const_cast<QMimeData *>(mimeData)))
- d->source = dragMime->source();
- else
- d->source = event->source();
+ d->source = dragSource;
d->dragPosition = event->position().toPoint();
if (d->drag) {
emit d->drag->positionChanged();