Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.13.1
-
None
Description
Tried to deal with drag and drop in Qml, I discovered cancelled drag / drop operations would shift items on their x/y axis while cancelling the operation.
Just drag a button from the testcase and let drop it anywhere, the original x,y position of the item would change for no reason.
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.12 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Row { height: 50 anchors { left: parent.left top: parent.top right: parent.right } Repeater { id: repeater model: 6 anchors { fill: parent } delegate: Control { id: control readonly property int index: model.index implicitWidth: parent.width / repeater.count implicitHeight: parent.height background: Rectangle { radius: 15 color: 'red' } contentItem: Label { text: qsTr('Button %1').arg(model.index) horizontalAlignment: Label.AlignHCenter } MouseArea { id: touchArea clip: true hoverEnabled: true drag { target: control axis: Drag.XAxis } anchors { fill: parent } onWheel: { // So event is forwarded wheel.accepted = false; } onPressedChanged: { if (pressed) { control.grabToImage(function(result) { control.Drag.imageSource = result.url; }); } } } Drag.active: touchArea.drag.active Drag.dragType: Drag.Automatic Drag.keys: [ 'TableViewHeader-dnd' ] Drag.mimeData: { 'TableViewHeader-dnd': control.index } Drag.supportedActions: Qt.CopyAction Drag.proposedAction: Qt.CopyAction Drag.onDragFinished: { // An annoying bug is shifting items 1px right when cancelling a drop operation... // Let unshift... // Qt.callLater(function() { // control.x = control.x - 1; // console.log('okok'); // }); } DropArea { id: drop keys: control.Drag.keys onEntered: { drag.accepted = drag.source !== control; } onDropped: { drag.accepted = false; } anchors { fill: parent } } opacity: drop.containsDrag ? 0.5 : 1.0 Keys.onEscapePressed: { control.Drag.cancel(); } } } } }