QT 控件里没有现成的 文件浏览器 。需要用到时 手撸极端繁琐,好在 QT诀窍。
基于 QTreeView + QDir 可以三行就构建一个文件浏览器。赞!
UI 里添加 QTreeView
在类构造中写下:
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath(QDir::currentPath());
ui->filetree->setModel(model);
我怎么知道?因为在QT文档里有说到。
在qt creator 帮助栏里搜索:QTreeView
就可以看到它的介绍了。所以没事多看文档少问路。