[Interest] Qml Drag n Drop Custom QQuickItem

Jérôme Godbout jerome at bodycad.com
Wed Sep 2 19:06:38 CEST 2015

I'm trying to add behaviors for drag n drop on a custom QQuickItem in C++
from Qml.

I have use inside the C++ part:
into the custom QQuickItem constructor.

I now receive event into custom handler:
dragEnterEvent(QDragEnterEvent* event)
inside the overload function. I can accept the event to begin receive :
dragMoveEvent(QDragMoveEvent* event)

This seem to work, but the event have a null source and no data inside to
base my choice to accept or not the event. The Qml attached
QQuickDragAttached element on my object seem to have the proper information
inside it. Source is set and valid, keys are presents, supportedActions and
proposedAction are ok there. But I don't received them inside my custom
QQuickItem handler of dragEnterEvent, the QDragEnterEvent::source is null,
only the supportedActions and proposedActions are set properly.

Here's a small example of Qml scripts

id: greenRect_
x: 200
y: 100
width: 20;
height: 20
color: "green"

Drag.active: dragArea_.drag.active
Drag.hotSpot.x: width * 0.5
Drag.hotSpot.y: height * 0.5
Drag.proposedAction: Qt.MoveAction
//Drag.source: greenRect_ // was already set to the proper value, try to
enforce it just to make sure, not difference
Drag.keys: ["green"]

id: dragArea_
anchors.fill: parent
drag.target: parent

            x: 300
            y:  300
            width: 200
            height: 200

I can drag the rectangle hover my item and receive the nearly empty event.
I guess I'm missing something fundamental here but I don't known what it is.

   1. Anybody have the mimeData map format?  Drag.mimeData: { 'hasText':
   true, 'text': "green" } ???
   2. Where does the Drag.keys end up inside the C++ ?
   3. Is my drag n drop Qml part done right?
   4. What is the accept drag n drop flow to end up with
   a dropEvent(QDropEvent *event) being called and handle properly.
      1. QDragEnterEvent must be Accepted
      2. QDragMoveEvent, (what to do in which case???) what happen if
      accepted or not exactly???
      3. When does the QDragLeaveEvent handler called exactly?
      4. How does one know when the drag was released (actually dropped)?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150902/9bc10e32/attachment.html>

More information about the Interest mailing list