[PyQt] can't drop external data onto QTreeView

danny shevitz at lanl.gov
Tue Sep 28 20:46:43 BST 2010


Howdy,

I'm having trouble dropping "text/plain" QMimeData onto a QTreeView.
The subtlety is that I am trying to drag onto an empty root. The context
is that I want to use drag and drop to help build the tree. If I have an 
existing item in the tree, then I can drop onto that just fine. The trouble
is that I want to drag below the bottom of the tree or onto an empty tree
and have that act like dragging onto the hidden root. 

I have read through all the examples I could find and looked through the 
documentation. I have overridden the following methods of QAbstractItem:
flags() supportedDropActions(), mimeTypes(), dropMimeData().

In the QTreeView I have set setAcceptDrop(True), setDropIndicatorShown(True),
and even overridden: 
    def dragEnterEvent(self,  event):
        if event.mimeData.hasFormat("text/plain"):
            event.acceptProposedAction()

    def dragMoveEvent(self, event):
       if event.mimeData.hasFormat("text/plain"):
            event.acceptProposedAction()

None of this lets me drop onto the background of the tree. Can anyone suggest
what I might need to override or set so that I can get dropMimeData in the model
to fire when I drop over an invalid item in the QTreeView?

thanks,
Danny



More information about the PyQt mailing list