QTreeView: Root node isn't shown
-
I would like to use a QTreeView to display my home folder and its subdirectories
Using the following Python code, the QTreeView excludes my home folder and only displays its subdirectories
Is there any settings in QTreeView I can made to include the root node (home folder)?@model = QFileSystemModel()
home_path = QDesktopServices.storageLocation(QDesktopServices.HomeLocation)
root_index = model.setRootPath(home_path)tree = QTreeView()
tree.setModel(model)
tree.setRootIndex(root_index)
tree.show()@ -
@
model = new QFileSystemModel;QString home_files = QDesktopServices.storageLocation(QDesktopServices.HomeLocation); QModelIndex homeIndex = model->parent(model->index(home_files)); QString home_path = model->filePath(homeIndex); QModelIndex root_index = model->setRootPath(home_path); treeView = new QTreeView; treeView->setModel(model); treeView->setRootIndex(root_index); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(treeView); setLayout(mainLayout);
@
You can use treeView->expand(), treeView->scrollTo() functions to expand the directory content and scroll to a specific item.