[SOLVED] Qt 6.2.2 - Drag & Drop broken in Quick?
-
[UPDATE]
further research leads to a solution of which I'm not sure if it's a work-around or just how things should always have been. The whole issue is that Qt's code examples change the parent of the dragged object but never reset it to a proper delegate container inside the ListView / GridView.For Qt's own example this means changing this part in Icon.qml:
states: [ State { when: dragHandler.active ParentChange { target: icon parent: icon.dragParent } AnchorChanges { target: icon anchors.horizontalCenter: undefined anchors.verticalCenter: undefined } } ]
To look like this:
states: [ State { when: dragHandler.active ParentChange { target: icon parent: icon.dragParent } AnchorChanges { target: icon anchors.horizontalCenter: undefined anchors.verticalCenter: undefined } }, /* reparent the item to it's former delegateRoot parent */ State { when: !dragHandler.active ParentChange { target: icon parent: delegateRoot } AnchorChanges { target: icon anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter } } ]
[ORIGINAL POST]
I've recently been trying to implement Drag & Drop reordering of a simple ListView's items.
Following the Quick samples was easy enough and everything is fine as long as the user drops an item in a new position (e.g. swaps places with another existing list item). However if the user cancels the drag for whatever reason then the dragged item will be randomly displaced inside the list view with no way to restore it's original position.I'm not sure if I'm doing something wrong or if this is a fundamental bug in how Quick handles Drag & Drop but it's reproducible in Qt's own samples as well (so it doesn't seem like my code is at fault):
Has anyone encountered this behaviour / knows a fix or workaround for it?
-
Thank you very much. I'm struggling a lot before I saw that post