On 19/10/10 18:13, danny wrote:
Howdy, I'm trying to impliment DnD in a QTreeView with a custom model
derived from QAbstractItemModel. I have run into the following question.

I want to be able to drag onto the tree from an external source. I also want to
do internal DnD to rearrange items. The mime type of internal drag is
'application/x-qabstractitemmodeldatalist'. My external data has a custom format
'application/x-whatever'. In order for the tree to accept external drops I
have overridden mimetypes() to return
['application/x-qabstractitemmodeldatalist','application/x-whatever'].

The problem is that if when I do internal dnd, The mimetype seems to be
'application/x-whatever', not 'application/x-qabstractitemmodeldatalist' like
I would expect. As a result, I can't tell the drag types apart.

Can anyone please enlighten me as to what I am doing wrong?

I'm don't really have working code, but the following snippets at least show
what I am trying. ( also tried types = types = ["application/x-whatever", ]
and this behaves exactly the same. If I take out the mimeTypes function, then
I can't do the external drop onto the tree.)

def mimeTypes(self):
    types = ["application/x-whatever",
             'application/x-qabstractitemmodeldatalist']
    return types

def dropMimeData(self, data, action, row, column, parent):
    # AT THIS POINT THE DATA IS ALWAYS 'application/x-whatever'
    # EVEN FOR INTERNAL DROPS
    if data.hasFormat('application/x-whatever'):
        if action==Qt.MoveAction:
           ...

when your reimplemented mimeTypes() method is called internally by qt, the first item in the returned list will be used to set the format.
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to