Pedro Witzel
Pedro Witzel

Reputation: 368

QTreeWidget: Find items on screen

I'm facing a performance problem with my QTreeWidget. Their values are updated periodically (every 100ms). To treat the value and display it demands a non-negligible time. So the more data, the slower the software runs.

Of course there are many areas that I can improve, but I think that the clearer is to not process data when not needed.

So the question is: how do I know which Items are in the area that is being shown in the screen?

I've tried to check for visibility (each item and visibilityRegion, that returns me the whole tree. Don't want that. I've tried to get the rectangle from the widget (frameReqt), same result as before.

Of course that if I don't update the whole model, once the user scroll, the other values, that were once hidden, will be out of data. But this is another concern.

Upvotes: 2

Views: 822

Answers (1)

Antwane
Antwane

Reputation: 22588

If you need to display a big amount of data in a tree view, you should probably use the Qt Model/View system: a QTreeView associated with a subclass of QAbstractItemModel. This is a much better option for your use case, and as far as I know, it already implements a smart update system (that asks the model for items only in a displayable range).

For example, think about reimplementing fetchMore() or canFetchMore() methods from the model class.

Upvotes: 3

Related Questions