Important: Please read the Qt Code of Conduct -

Drag and Drop + MIME Data

  • Hello there,

    my goal is to implement a Drag'n'Drop mechanism as part of a bigger application. Basically I use a QQuickWidget to display a Flickable which is filled by a Repeater with multiple items. Some of these items need to interact with each other by dragging one of them onto another. This should trigger a C++ method which needs data about the source of the drag.

    The best approach would be to put the relevant data into the DragEvent as MIME Data right?
    Now the problem is that my DropAreas accept the drops but there is no data in the DragEvent that is available in the onDropped() slot.

    This is the code for the items that need to be dragged:

    @import QtQuick 2.0

    Location {
    x: StationPosXCoord
    y: StationPosYCoord
    z: 10

    locationColor: "#fed505"
    Behavior on y {
        NumberAnimation { }
    Behavior on x {
        NumberAnimation { }
    Drag.proposedAction: Qt.CopyAction
    Drag.hotSpot: Qt.point(dragArea.mouseX, dragArea.mouseY)
    Drag.mimeData: { "text/plain": "asdf" }
    MouseArea {
        id: dragArea
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton parent
        drag.filterChildren: true


    And this is some of the code that uses the DropArea:

    @import QtQuick 2.0

    Location {

    Rectangle {
        anchors.fill: parent
        color: locationColor
        border.color: "black"
        border.width: borderWidth
        opacity: dropArea.containsDrag ? 0.5 : 1
        DropArea {
            id: dropArea
            anchors.fill: parent
            onEntered: print("entered");
            onExited: print("exited");
            onDropped: {

    The opacity of the Rectangle that contains the DropArea is reacting properly and also the onDropped() slot is called. The weird thing is that the attached properties like "proposedAction" and "hotSpot" behave as expected, but the "mimeData" one does not since the output of drop.text is empty.

    Am I missing something or doing something wrong? Any help is much appreciated!

    Cheers, Tobi

  • Well, I think you can get the mouse press and positionChanged signal on QML and process the QDrag on C++ . It's the acceptable solution now

  • FYI: accessing the Drag.mimeData by drop.text works for me with Qt 5.5 now. This way I can also drag and drop to external text editors, for example.

Log in to reply