PDA

View Full Version : QTreeView + Custom QStandardItemModel + DnD = frustrutating



NIteLordz
26th January 2015, 16:45
So i have a custom QTreeView and a custom QStandardItemModel and they are functioning well. I wanted to add in drag and drop to this, however, i have now encountered some frustration.

I have re-implemented dragEnterEvent(), dragMoveEvent(), and dropEvent(). I can trace when an item starts dragging, and when i am ready to drop it. Now is where the problem occurs, dropMimeData() is never called within the custom QStandardItemModel.

Within the dropEvent, i have verified that the item is being dragged properly. I wanted to implement dropMimeData() so that i could encode the QModelIndexList of selected indexes.

Is there anything in particular i should be checking for ?

I am using this as a tree for a scene hierarchy.

A
|_B
|_C
|_D

where i want to drag C to A.

thanks for any help or suggestions.

d_stranz
26th January 2015, 20:52
If you have reimplemented QAbstractItemModel::canDropMimeData(), are you sure it is returning true when you want it to? Have you reimplemented QAbstractItemModel::mimeTypes() to support your custom mime type if the default is unsuitable? If so, have you also reimplemented the mimeData() and dropMimeData() methods to support your mime types?

You might want to take a look at the Drag and Drop example programs.

NIteLordz
26th January 2015, 21:10
i have looked at them :(

i did not reimplement canDropMimeData() though, i will investigate that. other than that, i have the other methods mentioned with my custom mime type.

d_stranz
26th January 2015, 23:20
You might have to customize canDropMimeData() to handle your custom mime type. The default implementation always returns true, but I am not sure if that is true only for the default mime type or for any type.