Drag and Drop in separate windows
-
I'm trying to do drag and drop between different windows. Code drag the same as in еxample externaldraganddrop. Problem: If after dragging one element from window to window to try to drag the other is dragged back first element. If before the next mouse click drag to make it dragged the item. What could I miss that?
-
Hi,
It's not really clear. Could you show an example of what is happening ?
-
Sorry for my english. :)
Code and video with bug:
@
import QtQuick 2.2
import QtQuick.Window 2.0Window {
ListView { id: list anchors.fill: parent model: 5 delegate: Rectangle { width: list.width height: 30 border.color: "black" border.width: 1 Text { anchors.fill: parent text: index } Item { id: draggable anchors.fill: parent Drag.active: mouseArea.drag.active Drag.hotSpot.x: 0 Drag.hotSpot.y: 0 Drag.mimeData: { "mediaItem": index } Drag.dragType: Drag.Automatic Drag.onDragStarted: { } Drag.onDragFinished: { } } MouseArea { id: mouseArea anchors.fill: parent drag.target: draggable } } } Window { visible: true Text { id:text anchors.fill: parent } DropArea { anchors.fill: parent keys: ["mediaItem"] onDropped: { text.text += drop.source.mimeData["mediaItem"] drop.acceptProposedAction() } } }
}
@"Video":http://youtu.be/8XFeAA_ry14
-
Do you have the same effect if you use the same code as the documentation ?
-
The code above is the same as in the "example from the documentation":http://qt-project.org/doc/qt-5/qtquick-externaldraganddrop-example.html but with a few changes.
-
That's why I asked you to run it unmodified so as to see whether you have the same strange behavior.
-
I'm not sure I'm understanding you correctly. Are you saying that with the code from the example, you get the same behavior you are currently getting with your original software ?
-
Sounds like this could be a bug. Have a look at the "bug report system":http://bugreports.qt-project.org to see if it's something known. If not please consider opening a new report providing a minimal compilable example that reproduce the behavior
-
I'm not able to see the video link, probably because the post is quite long ago.
The issue that I see from the code above is the data is not able to be transferred from the drag area to the drop area between different windows.To resolve the issue, I had save the value in the property of the drag area, and retrieved this value from the drop area.
Here's the full code. Code changes are commented as //Changes hereimport QtQuick 2.2 import QtQuick.Window 2.0 Window { width: 800 height: 600 visible: true ListView { id: list anchors.fill: parent model: 5 delegate: Rectangle { width: list.width height: 30 border.color: "black" border.width: 1 Text { anchors.fill: parent text: index } Item { id: draggable anchors.fill: parent property var saved_value //Changes here Drag.active: mouseArea.drag.active Drag.hotSpot.x: 0 Drag.hotSpot.y: 0 Drag.mimeData: { "mediaItem": index } Drag.dragType: Drag.Automatic Drag.onDragStarted: { saved_value = index //Changes here } Drag.onDragFinished: { } } MouseArea { id: mouseArea anchors.fill: parent drag.target: draggable } } } Window { visible: true Text { id: text anchors.fill: parent } DropArea { anchors.fill: parent keys: ["mediaItem"] onDropped: drop => { text.text += drop.source.saved_value //Changes here drop.acceptProposedAction() } } } }