[PyQt] question on drag and drop

danny shevitz at lanl.gov
Tue Oct 19 18:13:41 BST 2010


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:
          ...

thanks,
Danny



More information about the PyQt mailing list