[PyQt] Pulling Abstract Item Data out of MimeData from Drag and Drop
mnations.lists at gmail.com
Sun Dec 14 19:02:30 GMT 2008
I'm a PyQt newb but fairly experienced with Python. So far I'm very
impressed with PyQt and have been able to get quite a sophisticated app up
and running in a short period of time. However I've hit a road block that so
far I have not been able to figure out.
I am using PyQt4 (Qt 4.4.3 with Python 2.6) on Windows XP. I am trying to
drag treeWidget info from one widget to another. The target widget will
likely be a modified tree widget as I need to combine a tree with a table to
get the proper data mix I need.
My first attempt was simply doing this:
> itemData =
However that apparently accessed a protected C++ function which quickly
threw an exception.
So then I tried to pull serialized data out using the data() function which
returned an empty set. Then I tried to pull data out using the items()
function passing in the mimeData object. Here is an example that I used to
try and get this working with another widget type.
> class ListBoxDnD(QListWidget):
> def __init__(self, parent):
> QListWidget.__init__(self, parent)
> def dropEvent(self, e):
> print self.items(e.mimeData())
This also returned an empty set. I thought if anything should translate the
data for me, this should do it. I know the data is there because I can see
the drag and drop working as data items are being correctly added to the
target widget. However the same mimeData is returning no data when I try to
access it directly. I can't figure that out.
I was able to find a work-around by overriding the drop function and just
grabbing the selected items from the source widget directly. This actually
works a little better than the default drag/drop behavior because I need the
selected tree items plus all the child items with a little extra data pulled
from a database. However at some point I may need to use the MimeData
functionality as it was originally intended, so hopefully someone will know
how to get this to work correctly.
Thanks ahead of time,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt