PDA

View Full Version : QTreeView: expandAll() and expandToDepth(int) not working



papillon
22nd October 2011, 23:39
I've the following code (QT 4.7):



QFileSystemModel *treeModel = new QFileSystemModel;
QTreeView *libTree = new QTreeView(mainFrame);
libTree->setModel(treeModel);
libTree->setItemsExpandable(true);
libTree->expandAll();


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

d_stranz
23rd October 2011, 22:45
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.

papillon
24th October 2011, 00:30
Thanks, will surely try this...