[PyQt] Item data on QTreeView

Diego diego.no.spam at gmail.com
Mon Jul 9 17:57:08 BST 2012

On Mon, Jul 9, 2012 at 3:42 AM, Andreas Pakulat <apaku at gmx.de> wrote:
> You could store it only in the first item of a row and always access it
> there. Another option would be have a dict of messages and use the
> row-number as key - this only works of course as long as your rows are not
> re-arranged frequently.
> Both approaches however duplicate some of the data though - everything thats
> displayed to the user. To solve that you'd have to write your own model
> subclass which directly works on the messages and returns the corresponding
> data from the data() function. With such a model you could also return the
> original message object when data() is called with a custom data role.
> Andreas

I think I will end up subclassing QStandardItemModel sooner or later
and will deal with this in the data() method.

Thanks for your help.

More information about the PyQt mailing list