Unsolved Drag and Drop to desktop or file manager
-
This one is kinda fun. I currently have drag from the desktop/file manager working as my DropArea gets a url for me to use. Now I am trying to detect the drop area outside of the application.
Drag.active: mouseArea.drag.active Drag.hotSpot.x: 0 Drag.hotSpot.y: 0 Drag.mimeData: { "text/uri-list": fileUrl } Drag.supportedActions: Qt.CopyAction Drag.dragType: Drag.Automatic Drag.onDragStarted: { } Drag.onDragFinished: { if(dropAction === Qt.CopyAction){ console.log("drag copy") } }
I have 2 problems.
- How do I detect if this landed in a DropArea or outside the app?
- How do I detect where it dropped outside the app? (there is no DropArea for this)
In the above code I see the "drag copy" message get printed as expected when dropping outside the app. I cannot see anything in the docs to indicate how to get the drop area/url that I dropped to outside the app. Is there a global drop area or something?
-
Replying here just because it's the first hit on google for
Drag.Automatic
: there is an answer to this question here: https://stackoverflow.com/questions/24532317/new-drag-and-drop-mechanism-does-not-work-as-expected-in-qt-quick-qt-5-3. In short, you should replaceDrag.active: mouseArea.drag.active
by
property bool dragActive: mouseArea.drag.active onDragActiveChanged: { if (dragActive) { Drag.start(); } else { Drag.drop(); } }
More details in the SO post, apparently you can see the different code flows in the QQuickDrag code. Note that
Drag.Automatic
does work as expected when you use aDragHandler
, just not when you use aMouseArea
.