New drag-and-drop mechanism does not work as expected in Qt-Quick



  • I've tried to implement drag and drop in Qt 5.3 using the new QML types "Drag":http://qt-project.org/doc/qt-5/qml-qtquick-drag.html, "DragEvent ":http://qt-project.org/doc/qt-5/qml-qtquick-dragevent.html and "DropArea":http://qt-project.org/doc/qt-5/qml-qtquick-droparea.html. This is the original example from the documentation of the QML Drag type with some small modifications:

    @import QtQuick 2.2

    Item {
    width: 800; height: 600

    DropArea {
        width: 100; height: 100; anchors.centerIn: parent
    
        Rectangle {
            anchors.fill: parent
            color: parent.containsDrag ? "red" : "green"
        }
    
        onEntered: print("entered");
        onExited: print("exited");
        onDropped: print("dropped");
    }
    
    Rectangle {
        x: 15; y: 15; width: 30; height: 30; color: "blue"
    
        Drag.active: dragArea.drag.active
        // Drag.dragType: Drag.Automatic
        Drag.onDragStarted: print("drag started");
        Drag.onDragFinished: print("drag finished");
    
        MouseArea {
            id: dragArea
            anchors.fill: parent
            drag.target: parent
        }
    }
    

    }@

    Expected behaviour: The small blue rectangle (drag target) can be dragged around with the mouse. If dragged over the larger green rectangle in the center of the window, this rectangle turns red and back to green when leaving. In addition, the signals dragStarted, entered, exited, dropped and dragFinished are emitted in time and the corresponding signal handlers print out their messages.

    Experienced behaviour:

    Depends on "Drag.dragType":http://qt-project.org/doc/qt-5/qml-qtquick-drag.html#dragType-prop (see commented line #23 above):

    Drag.dragType is NOT set (default is Drag.Internal): Drag and drop works as described, but only the signals entered and exited are emitted. The other signals (dragStarted, dragFinished and dropped) are suppressed. So there is no way to react to the drop in the DropArea.

    Drag.dragType is set to Drag.Automatic: All of the signals are emitted now, but the blue rectangle (drag target) does not move with the mouse. Instead, the mouse cursor changes its shape to visualize possible drop targets. After the mouse has been released, the blue rectangle jumps to the latest mouse position.

    Neither of these two variants are pleasing. How can I get all signals and still be able to drag around the drag target? Unfortunately the documentation is everything but clear about drag-and-drop in QML, especially about the ominous Drag.dragType.

    Sidequest: Can a DropArea dynamically decline a drag/drop operation, (e.g. after inspecting the drag.source)? This does not work:
    @onEntered: drag.accepted = false@




  • Lifetime Qt Champion

    Hi,

    Sounds that there something fishy going on either with the doc or Qt, you should bring this question to the interest mailing list. You'll find there Qt's developers/maintainers (this forum is more user oriented)



  • OK, thanks. This explains why I didn't get any response so far... ;)


  • Lifetime Qt Champion

    Not necessarily, you might also have conditions that other users didn't experience so far ;)



  • This are my greatest fears: I've got a problem and I'm the only one...worldwide... ;)


  • Lifetime Qt Champion

    Don't be so sure, others may have just not found out about it yet ;)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.