[PyQt] Item data on QTreeView

Andrew Suffield asuffield at suffields.me.uk
Mon Jul 9 08:12:57 BST 2012


On Sun, Jul 08, 2012 at 07:02:27PM -0300, Diego wrote:
> When a row is selected in the QTreeView, I need to be able to access
> the object whose attributes are being displayed in that row. I don't
> know how to properly do that, and the only thing that worked for me is
> to store the original object in each and every item I create, as in
> (1), (2) and (3) in the code snippet above. It appears to me as a very
> inefficient way of solving this problem and I think there must be a
> much better solution for it.

The cost of storing an extra reference in each object is on the order
of a few bytes per item. Unless you have millions of items in your
treeview (which generally sucks regardless of what you do, treeviews
don't scale that well), this adds up to a tiny amount of memory.

It is unlikely that a much better solution exists. This is premature
optimisation.


More information about the PyQt mailing list