Well, I think I have a possible solution for you.
Keep in mind that I am a complete neophyte in this area, so there is no guarantee that it a) works b) is a worthy solution c) does not make the "real" programmer quit his lunch.
I did the conversion of the entire ancestor tree of a specific item to a text list of pairs of row column pairs. (i.e., list the row and column of the item being dragged, the row and column of its parent, the row and column of the parent, etc.) until we return to the invalid index - that is, the root)
It looks something like this (this example shows that the item being dragged has four depth levels):
2;0,1;0,5;0,1,0 ^ ^ ^ ^ | | | | | | | great grandparent (and child of the root item) | | | | | grandparent | | | parent | item being dragged
Later, in the dropMimeData function, I cancel the list (so that it reads from the root as long as it is being dragged) and create indexes each time until I return to the initially dragged item.
Here are the code snippets that make everything work. Again, I cannot guarantee that this is a good idea, it just works and does not require you to serialize your python objects in ByteArray.
Hope this helps.
#--------------------------------------------------------------------------- def mimeTypes(self): """ Only accept the internal custom drop type which is plain text """ types = QtCore.QStringList() types.append('text/plain') return types
source share