diff options
author | Shawn Rutledge <[email protected]> | 2023-09-20 18:25:27 +0200 |
---|---|---|
committer | Shawn Rutledge <[email protected]> | 2023-11-21 02:25:12 +0200 |
commit | a3dea1b4f8e20babb84c501e578a9208961b7ca7 (patch) | |
tree | 3c91f130e0e247bc2261edc640421d94e9c263c7 | |
parent | bda6820f87fddac256abdf7c8d3b562a90ab6ed1 (diff) |
doc: Set Drag.imageSource before Drag.active to avoid race condition
grabToImage() is asynchronous. 4b982c744f538a24e21a2af146c45f93d27dd1cb
started it on mouse press, which generally gave it enough time before
the QDrag became active; but 5971a6faaa1124f5ef3f0b42d4ed0298cf8096a3
changed it to call grabToImage() in DragHandler.onActiveChanged, which
means waiting until the drag threshold is exceeded. (DragHandler doesn't
offer a way to detect when the point is pressed. One could probably use
a separate TapHandler or PointHandler just to detect the press; but
that's also inefficient and inconvenient.) If we also bind Drag.active
to DragHandler.active, it's very likely that the binding is updated
before grabToImage() is done; and as documented, setting imageSource
after the drag has started has no effect (that in turn is a limitation
in QDrag and the platform support, probably a limitation on actual
platforms). So just wait until the screen-grab is done before setting
Drag.active, as a workaround for now.
This is a step back in declarativeness, using JS rather than a binding.
But setting imageSource to a screen-grab unfortunately requires JS
anyway; so we might as well delay making the Drag active until the
screen-grab is done.
Fixes: QTBUG-112673
Fixes: QTBUG-115491
Pick-to: 6.2 6.5 6.6
Change-Id: I0317613aa0288ad99b55ebd8a470500432b2ea02
Reviewed-by: Richard Moe Gustavsen <[email protected]>
-rw-r--r-- | src/quick/doc/snippets/qml/externaldrag.qml | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/quick/doc/snippets/qml/externaldrag.qml b/src/quick/doc/snippets/qml/externaldrag.qml index 072612f0c8..723701a7a5 100644 --- a/src/quick/doc/snippets/qml/externaldrag.qml +++ b/src/quick/doc/snippets/qml/externaldrag.qml @@ -12,7 +12,6 @@ Item { color: "green" radius: 5 - Drag.active: dragHandler.active Drag.dragType: Drag.Automatic Drag.supportedActions: Qt.CopyAction Drag.mimeData: { @@ -30,8 +29,11 @@ Item { onActiveChanged: if (active) { parent.grabToImage(function(result) { - parent.Drag.imageSource = result.url; + parent.Drag.imageSource = result.url + parent.Drag.active = true }) + } else { + parent.Drag.active = false } } } |