Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
None
-
5.2.0
-
None
-
If this is considered useful, the complete source of the application in question is available at https://code.launchpad.net/~adamreichold/qpdfview/trunk with the discussed change being introduced in revision 1419.
Description
Similarly to the closed #QTBUG-8889, I was trying to implement restoring the expansion state of a tree view after changing the model. I settled for storing the expansion state for each item as a user role item datum in the model to reapply the expansion state after a model change. However, this has the serious performance issue that even ineffectual calls to QTreeView::setExpanded take a few milliseconds for top-level items, so that restoring the trivial expansion state of a model with only a few hundred top-level items (even without any children) can take several seconds. (From reading qtreeview.cpp, I have not yet understood why this affects top-level items so much more than proper child items.)
The problem was resolved by explicitly checking for ineffectual expand/collapse operations, i.e. by replacing
> setExpanded(index, expanded);
by
> if(isExpanded(index) != expanded)
which I would hence suggest for inclusion into upstream, i.e. make QTreeView::setExpanded and/or ::expand and ::collapse check whether the specified index is already expanded resp. collapsed before performing any possibly expensive computations.