[Interest] Subclassing QTreeWidgetItem together with QObject

Andrej Kacian andrej at kacian.sk
Fri Nov 27 15:01:00 CET 2015


On Fri, 27 Nov 2015 10:39:19 +0100
André Somers <andre at familiesomers.nl> wrote:

> > Or is there a better way to do what I described?
> >  
> Perhaps, depending on what you really want to achieve. Instantiating 
> QObjects everywhere is quite expensive. If you have a lot of items in 
> your tree, it may cause performance issues.

Hm, performance is a good point, I did not think of that.

Basically, until now I have subclassed QTreeWidgetItem just to overload
its operator<(), because I need custom sorting in this particular tree
widget.

In the Qt::UserRole column, I hold a pointer to an object, and I need
to update displayed columns when this object changes.

At the moment, I am handling this via a custom slot on QTreeWidget
(the objects emit a signal when they change), which looks up the correct
item to update and updates its columns. It works fine, but I thought
that it would be more elegant to have each item "listen" for changes in
its object directly. Hence the idea to add the QObject inheritance to my
QTreeWidgetItem subclass.

Regards,
-- 
Andrej



More information about the Interest mailing list