[PyQt] QAbstractListModel.setData gets passed a QVariant that cannot be converted to user data type
thorben.kroeger at iwr.uni-heidelberg.de
Fri Jun 3 21:00:42 BST 2011
I'm implementing a QAbstractListModel derived class in PyQt that uses a
custom data type.
However, in QAbstractListModel.setData(index, value, role =
Qt.EditRole), I get passed value as a QVariant, and I cannot convert it
to my custom type:
yields: "TypeError: unable to convert a QVariant back to a Python object"
Please find the short code (<300 lines, adpated from the StarDelegate
example of Qt) attached.
The problem occurs when using drag/drop to reorder the items inside the
view. You'll see the above error printed, and the dropped item is
replaced by a new instance of StarRating, which has 5 stars by default.
(Another problem I have with this example is that dragging items on top
of empty space in the QListView deletes the item, though I specified
Qt.MoveOnly in supportedDropActions... Maybe you happen to know what the
problem is here as well?)
How can I fix this?
P.S.: I posted this to stackoverflow
but believe this list is a better place for that question...
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 9863 bytes
Desc: not available
More information about the PyQt