I am using QTreeView
together with QFileSystemModel
to display a tree of folders. My code displays the contents of the C drive directly.
However, I want the topmost level of the tree to first display a list of all available drives that can be expanded.
How can this be implemented? Here is my code
#include <QApplication>
#include <QTreeView>
#include <QFileSystemModel>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath("");
model->setFilter(QDir::Drives | QDir::NoDotAndDotDot | QDir::AllDirs | QDir::NoSymLinks);
QTreeView *treeView = new QTreeView;
treeView->setModel(model);
treeView->setRootIndex(model->index(QDir::rootPath()));
for (int i = 1; i < model->columnCount(); ++i) {
treeView->setColumnHidden(i, true);
}
treeView->setColumnWidth(0, 250);
treeView->setWindowTitle("QFileSystemModel Example");
treeView->resize(600, 400);
treeView->show();
return app.exec();
}