Getting AbstractItemData from drag/drop in Python
I'm trying to drag/drop info from a TreeWidget into a TextBox. I have been able to modify the TextEdit box to override the dragEnterEvent like this:
class TextEdit(QtGui.QTextEdit):
def __init__(self, title, parent):
QtGui.QTextEdit.__init__(self, title, parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
if event.mimeData().hasFormat('text/plain'):
event.accept()
elif (event.mimeData().hasFormat("application/x-qabstractitemmodeldatalist")):
print event
itemData = event.mimeData().retrieveData("application/x-qabstractitemmodeldatalist", QtCore.QVariant.List)
The drag is working up until the point I try to actually retrieve the data. At that point I get an unhandled Runtime Error saying "no access to protected functions or signals for objects not created in Python". Obviously I am not retrieving them in the correct format. How do I do that?
Thanks
Re: Getting AbstractItemData from drag/drop in Python
Anyone? I've tried to cast it into something else and modify the data before-hand, either way I can't get the data out once it gets packed into the MIME format.
I've seen a couple of other places where this was done before in PyQt3. Is this just something that doesn't work in PyQt4.
Re: Getting AbstractItemData from drag/drop in Python
One other aspect that doesn't make sense is that if I pass the mimeData directly into the items() function it should translate the data and give back a list:
class ListBoxDnD(QListWidget):
def __init__(self, parent):
QListWidget.__init__(self, parent)
self.setDragEnabled(True)
self.setAcceptDrops(True)
...
def dropEvent(self, e):
print self.items(e.mimeData())
However, even though I see the data passed into the 2nd treeWidget (so I know the data is there) this function returns an empy set []. I should at least be getting data back from this function.
The only work-around I've found so far is to simply override the drop and go grab the selected items from the original tree. I guess that will work, but I'd like to know why this other stuff isn't working.