Results 1 to 3 of 3

Thread: QTreeView: expandAll() and expandToDepth(int) not working

  1. #1
    Join Date
    Jan 2011
    Posts
    55
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QTreeView: expandAll() and expandToDepth(int) not working

    I've the following code (QT 4.7):

    Qt Code:
    1. QFileSystemModel *treeModel = new QFileSystemModel;
    2. QTreeView *libTree = new QTreeView(mainFrame);
    3. libTree->setModel(treeModel);
    4. libTree->setItemsExpandable(true);
    5. libTree->expandAll();
    To copy to clipboard, switch view to plain text mode 

    expandAll() doesn't produce what I expected (i.e. automatically expand all nodes), and expandToDepth(int) doesn't work either. Any idea why? Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeView: expandAll() and expandToDepth(int) not working

    Probably has something to do with the fact that the QFileSystemModel is dynamically populated by the QFileSystemWatcher. If you have a large file system, then the model will almost certainly have not been fully populated by the time you call expandAll(), so only the items that have been populated will be expanded.

    Try this same experiment with the code I posted in response to your other thread. Calling expandAll() just before the end of the MultiModelWindow constructor -does- result in a fully-expanded tree. Takes a while because the tree is so deep, but when it does finally appear, all tree nodes are expanded.

  3. The following user says thank you to d_stranz for this useful post:

    papillon (23rd October 2011)

  4. #3
    Join Date
    Jan 2011
    Posts
    55
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTreeView: expandAll() and expandToDepth(int) not working

    Thanks, will surely try this...

Similar Threads

  1. Replies: 2
    Last Post: 31st July 2013, 17:06
  2. Replies: 2
    Last Post: 15th February 2011, 14:10
  3. QTreeView edit() not working.
    By billw in forum Qt Programming
    Replies: 0
    Last Post: 20th August 2010, 17:26
  4. QTreeWidget and expandall() function
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 31st July 2007, 22:49
  5. Replies: 1
    Last Post: 28th February 2007, 08:34

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
  •  
Qt is a trademark of The Qt Company.