Drag and Drop support for TreeView
Unsolved
QML and Qt Quick
-
Hi everyone, I'm trying to implement drag and drop for TreeView. I've ended up with the following QML code for my view:
TreeView { id: tree_view model: root.m_model // defined in C++ selectionModel: ItemSelectionModel { id: selection_model } DropArea { id: drop_area anchors.fill: parent onDropped: (drag) => { // <-- never called console.log('DropArea onDropped'); var from = drag.sourceDelegate.visualIndex; var to = visualIndex; root.m_model.move(from, to); } } delegate: TreeViewDelegate { id: tree_delegate Drag.source: drag_handler Drag.active: drag_handler.active DragHandler { id: drag_handler target: parent cursorShape: Qt.ClosedHandCursor onActiveChanged: { console.log('onActiveChanged ', active); if (drag_handler.active) drag_handler.parent.Drag.drop() } } } }
The problem is that onDropped() is never called. Thus moving tree elements does nothing. I'm missing something obvious here, but what exactly? My Qt version is 6.4.