[PyQt] QMap, QHash?

Phil Thompson phil at riverbankcomputing.com
Fri Nov 16 22:20:05 GMT 2012


On Fri, 16 Nov 2012 10:34:12 -0800, David Cortesi <davecortesi at gmail.com>
wrote:
> Working on implementing a List model using QAbstractListModel and
> would like to implement (set)itemData which returns a QMap.
> 
> QMap seems to be Qt's version of a dict, a list of key:value pairs.
> (QHash is apparently similar.) The point of itemData/setItemData is to
> return or set the data for every property role of an item in one go,
> instead of multiple calls to data/setData. (*)
> 
> Looking at the PyQt4 class dictionary I don't see QMap listed (nor
> QHash). It would be rather cool if PyQt4 would support it with
> automatic conversion to/from a dict, the way it happily converts
> between u-strings and QStrings. But any support would be good.
> 
> Dave Cortesi
> 
> (*) I think itemData/setItemData is important because if your item has
> one or more userData roles, this is the only way Qt would know they
> exist to  include them when dragging an item. Or am I imagining this?
> Drag/drop of model items in a view is a bit of a black hole to me.

Have you tried...

>>> from PyQt4.QtCore import QAbstractListModel
>>> help(QAbstractListModel.itemData)

Phil


More information about the PyQt mailing list