I'm using a QAbstractItemModel, which is bound to a tree-view. Drag & drop is currently handled by the model, which calls insert/remove rows (so I implemented insert/remove rows, data and setData.) As I only allow move drag & drop operations within a single view, is it possible to capture the drag & drop operation at the model level and add an own handler? In my case, moving a node means just setting a new parent pointer; right now I return the whole subtree in data () in a user-data structure, then I create dummy nodes in insertData and I copy over using setItemData, which is a bit overkill.

Ideally, I would like to have some move (QModelIndex& from, QModelIndex& to) to override, but I couldn't find a way to do this. What's the recommended way to implement this?

(Details on the current data flow)
  • itemData returns the subtree of an item in Qt::UserRole + 1
  • insertRows just creates a dummy and waits for setItemData to pass in the real data
  • setItemData rebuilds the tree
  • removeRows deletes nodes including all children