Solved Drag and Drop in QabstractListModel
-
Hi,
I have C++ Model and that model i have given to Qml ListView. I want to implement Drag and Drop in ListView and On Drag-Drop Model items should get swap. I am able to Drag-Drop But as my Model is Define in C++, I am not able to Swap items.I know move() method is there for Swap in Model. But for accessing move() method we need "from,to" parameters. I am able to get "from" parameter index. But how will i get "to" parameter index i.e., Drop-Index.
Thanks,
Bhushan Sure -
Please include
import QtQml.Models 2.3
or latest supported by your Qt Version.You can refer a sample code Using drag and drop with ListView.
And below is simple example of using DropArea & bit modified.
delegate: Item { id: delegateItem --- --- DropArea { id: dropArea anchors { fill: parent; margins: 10 } onEntered: { listView.model.move(listView.dragItemIndex, delegateItem.DelegateModel.itemsIndex, 1); // Use your C++ model here and implement the move() } } }
All the best.
-
@Pradeep-P-N Thank you very much :)