[PyQt] Item.data() and python dictionary

Phil Thompson phil at riverbankcomputing.com
Fri Jun 12 17:00:17 BST 2009


On Fri, 12 Jun 2009 16:48:36 +0100, IT <it at geolab.org.uk> wrote:
> newbie question. I've searched for this but still not sure how to
proceed.
> 
> What I want to do it store a dict in item data eg
> 
> job = {'job_no': 345, 'status': 20, 'foo': 10}
> 
> si = QtGui.QStandardItem(job['job_no])
> si.setData( QtCore.QVariant( job ) )
> 
> Problem is how do I convert it back, eg on a click event..
> 
>     def on_table_clicked(self, modelIndex):
>         print "on_table_clicked row/col", modelIndex.row(), 
> modelIndex.column()
>         data = self.model.itemFromIndex( modelIndex ).data()
> 
>         print data   # .toPythonDictionary()

Assuming a current version...

    data.toPyObject()

Phil


More information about the PyQt mailing list