[Helped, if not solved!] sizeHintForColumn eating all the CPU (presumably by being called an awful lot)
I have a QTreeView, and it gets populated with information. Not an enormous amount, but as far as I can tell (not having written it) it looks like a standard QTreeView, being given a model derived from a QAbstractItemModel.
The QTreeView shows two columns, one of which contains the expandable tree bits and the other contains some subsidiary information. As time goes on, new items can be inserted, and they will either be inserted at the bottom, or if they go with something already in the model, rows get added.
For example, it's information about files, and it might end up looking something like this:
|__ info A
and then the next update will be "info MORE" for file_one.cpp, so then the on screen view becomes
|__ info A
|__ info MORE
All pretty simple. There could be thousands and thousands of these; there is a big queue of messages being processed, and each one adds something to the model.
It's taking forever. So I profiled it (expecting to see that the message processing was slow, or some other such, but I've played this game before and I know that the only facts come from measuring), using perf, and one function is taking up 70% of the time; QTreeView::sizeHintForColumn
My guess is that this gets called every time something is inserted, because the QTreeView wants to resize the column. Is that right? If so, is it something I can stop or optimise?
Alternatively, could I tell the QTreeView not to update while the queue of messages is being processed? I think that might be acceptable; to just show them all once the queue is finished.
I've got various ideas, but I'm not so stupid that I won't ask more experienced people :)
If you know that all your rows have the same hight you can use the uniformRowHeights property of the QTreeView.
Then you can optimize some more by doing batch updates rather than update each every row as fast as possible.
Hope it helps
I think I'm really hoping for some way to tell it not to bother resizing columns.
You can try to play with QHeaderView::setResizeMode
I think it has helped a bit, thanks.