[SOLVED] Need to show Only File System folders in QTreeView.
-
Hi All,
I want to display only folders in my QTreeView with the following order like@
->Desktop
|->MY Computer
|-> C:
|-> D:
|->Control Panel@
like that.....my codes are here
@
CTestDlg::CTestDlg(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
//QFileSystemModel *model = new QFileSystemModel(this);QDirModel *model = new QDirModel(this); QString home_files = QDesktopServices::storageLocation(QDesktopServices::HomeLocation); QModelIndex homeIndex = model->index(home_files); //QString home_path = model->filePath(homeIndex); //QModelIndex root_index = model->setRootPath(home_path); ui->treeLocalFolders->setModel(model); ui->treeLocalFolders->setRootIndex(homeIndex);
}
@
Here i can see all the folders with corresponding files are displaying in my QTreeView
...and also the order was not correct...which i am expecting like above
Please throw some light on this... -
Did you try to "setFilter":http://doc.qt.nokia.com/latest/qfilesystemmodel.html#setFilter on model ?
-
Try something like this ...
@
QFileSystemModel fileSystemModel = new QFileSystemModel(QDir::NoDotAndDotDot | QDir::Dirs);
QModelIndex modelIndex = fileSystemModel->setRoorPath(fileSystemModel->myComputer());
ui->treeLocalFolders->setRootIndex(modelIndex)
@