Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

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

$
0
0
I’ve tried to implement drag and drop in Qt 5.3 using the new QML types Drag [qt-project.org], DragEvent [qt-project.org] and DropArea [qt-project.org]. 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 [qt-project.org] (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

Viewing all articles
Browse latest Browse all 4972

Latest Images

Trending Articles



Latest Images