PDA

View Full Version : preserve collapse/expand of a QTreeView



yazwas
6th November 2009, 23:36
Hello all,

I have a standard QTreeView model/view instance where I populate its items from database with multiple levels and sublevels

What I want to do is to save the way the expansion structure has become (when the user closes the application), so next time the user opens the application, or new data is added from the database (re-populate the model) I will still get the same view, with the same nodes expanded or collapsed as they were earlier.

is that possible at all? and if so, what is the best way to do it

Thanks all

aamer4yu
7th November 2009, 09:49
I guess you will need to write your own method for that.
Simple way would be to iterate over the treeview and save the state of each item in a xml format. Something like -

<Root>
<Item index ="0" hasChildren="true" expanded="true/false" >
<Item index ="0" hasChildren="false" expanded="false" />
<Item index ="1" hasChildren="false" expanded="false" />
</Item>
<Item index ="1" hasChildren="false" expanded="false" />
.......
</Root>