How to emit onDropped in QML drag n drop example?
6,313
Apparently a drop needs to be generated explicitly by calling the drop() method on the Drag object
Try adding this line inside of the MouseArea
, just above drag.target: parent
onReleased: parent.Drag.drop()
Related videos on Youtube
Author by
xubuntix
Updated on September 18, 2022Comments
-
xubuntix almost 2 years
In the qml documentation there is a drag'n'drop example:
import QtQuick 2.0 Item { width: 200; height: 200 DropArea { x: 75; y: 75 width: 50; height: 50 onDropped: console.log("dropped") onEntered: console.log("entered") Rectangle { anchors.fill: parent color: "green" visible: parent.containsDrag } } Rectangle { x: 10; y: 10 width: 20; height: 20 color: "red" Drag.active: dragArea.drag.active Drag.hotSpot.x: 10 Drag.hotSpot.y: 10 MouseArea { id: dragArea anchors.fill: parent drag.target: parent } } }
I have added the two lines with "onDropped" and "onEntered". While "onEntered" is triggered by dragging the small rectangle, I can not make the "onDropped" to trigger.
What do I have to do to make it trigger?