Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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()
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.