最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Show list of drives in QTreeView - Stack Overflow

programmeradmin5浏览0评论

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();
}
发布评论

评论列表(0)

  1. 暂无评论