Results 1 to 2 of 2

Thread: preserve collapse/expand of a QTreeView

  1. #1
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default preserve collapse/expand of a QTreeView

    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

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: preserve collapse/expand of a QTreeView

    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 -
    Qt Code:
    1. <Root>
    2. <Item index ="0" hasChildren="true" expanded="true/false" >
    3. <Item index ="0" hasChildren="false" expanded="false" />
    4. <Item index ="1" hasChildren="false" expanded="false" />
    5. </Item>
    6. <Item index ="1" hasChildren="false" expanded="false" />
    7. .......
    8. </Root>
    To copy to clipboard, switch view to plain text mode 
    Last edited by aamer4yu; 7th November 2009 at 10:04.

Similar Threads

  1. Need help Updating QTreeView model (QAbstractItemModel)
    By iraytrace in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2009, 22:49
  2. One Model, Two Views (QTreeView and QTableView)
    By dgarrett97 in forum Newbie
    Replies: 2
    Last Post: 14th September 2009, 18:10
  3. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 21:22
  4. QTreeView: Holding a line on screen
    By gri in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 11:42
  5. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 06:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.