Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Drag and drop in QTreeView - where do I get the dragged data?
I've got a QTreeView. I set some values to enable drag and drop within the QTreeView (so the user can move things around).
Now, the user can drag an item. When they release it, insert rows is called on the model. The call contains enough information for me to work out exactly where I need to insert the item. But I don't have the actual item that has been dragged. How do I know which item has been dragged so that I can copy that item's data and insert it as a new row?
Since you are doing an internal move you don't need to copy any data or are you trying to do something different ?
No, I'm just trying to do an internal move.
Maybe I've missed the point of this entirely. I have some items in the treeview, and I click one and drag it somewhere else and let go of the mouse button, and the next function that I see being called is my model's override of "insertRows".
What I need to do is, in my model, identify the item that was dragged, remove it from its parent's list of children, and put it on some new item's list of children (i.e. the suitable new parent where the user dropped it)
But I don't know what item the user dragged. The insertRows function is being called, but how do I know what the dragged item was?
I can't make head nor tail of the documentation on this one. There seem to be so many different options being described by drag and drop. I've just got the simplest (?) case; dragging something in a QTreeView, to somewhere else in that QTreeView.
bq. The standard views automatically support internal drag and drop, where items are moved around to change the order in which they are displayed. bq.
but I can't see how to "turn on" that automatic support.
You don't have to turn it on, it's in automatically.
jerome_isAviable last edited by
if you want to play with drag and drop, you need to implement a model class and add member function need to do it... for flags and also for handle your datas type droped inside... it is not really simple (for my level).
if you need an exemple of a code model (QStandardItemModel) for a qtreeview that use drag and drop, i can pastebin it for you... but again, it is not really simple to use.
InternalMove is not as complicated as the other modes