PDA

View Full Version : by default how to make QTreeView in extended state



narlapavan
23rd July 2012, 14:30
i have a QTreeView ,and its pointing to some location, so i can see all the folders which are in that location . By default all the sub folders are in collapse mode how to make it to EXTENDED mode

wysota
23rd July 2012, 15:37
QTreeview::expandAll()

narlapavan
23rd July 2012, 15:43
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath(QDir::currentPath());
QString strPath ="/home/Desktop/PATHS";
ui->treeView->setItemsExpandable(true);
ui->treeView->setModel(model);
ui->treeView->setRootIndex(model->index(strPath));
ui->treeView->expandAll();

i tried these too but it din't work.

wysota
23rd July 2012, 15:52
Since QFileSystemModel works in an asynchronous fashion, you need to call expandAll() only after QFileSystemModel::directoryLoaded() signal is emitted for the directory you need. Alternatively you can connect to that signal and upon receiving the path that has been completed, convert it to QModelIndex using QFileSystemModel::index() and then call QTreeView::expand() on the calculated index. Then you'll be expanding directories as they are being scanned.