Looking at the tree view's source code, I see that the expanded states are saved inside the tree view itself, using a
QList container :
|
Source code
|
1
|
QList<QPersistentModelIndex> expandedIndexes;
|
Basically, when an item is expanded, its index is added to that
expandedIndexes list. When an item is collapsed, its index is removed from that list. Now, the tree view declares this list private -- you cannot access it directly. Your only access functions are those I gave you before :
isExpanded() and
setExpanded().
And inside
setModel(), there's the following instruction :
|
Source code
|
1
|
expandedIndexes.clear();
|
I see two solutions to your problem :
A/ When unsetting a model, create by your own a list of expanded indexes using
isExpanded() and later apply it using
setExpanded(). The restore code should start with
setUpdatesEnabled(false) and end with
setUpdatesEnabled(true).
or
B/ Create as many tree views as tree models.