1个回答
展开全部
这个可以使用QTreeview和QFileSystemModel:官方文档例子如下:
It is simple to construct a tree view displaying data from a model. In the following example, the contents of a directory are supplied by a QFileSystemModel and displayed as a tree:
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath(QDir::currentPath());
QTreeView *tree = new QTreeView(splitter);
tree->setModel(model);
如果要使用QTreeWidget 就要使用QFileInfo对文件夹进行遍历,挨个添加到QTreeWidget中。有关QFileInfo请参考帮助文档:http://qt-project.org/doc/qt-4.8/qfileinfo.html
It is simple to construct a tree view displaying data from a model. In the following example, the contents of a directory are supplied by a QFileSystemModel and displayed as a tree:
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath(QDir::currentPath());
QTreeView *tree = new QTreeView(splitter);
tree->setModel(model);
如果要使用QTreeWidget 就要使用QFileInfo对文件夹进行遍历,挨个添加到QTreeWidget中。有关QFileInfo请参考帮助文档:http://qt-project.org/doc/qt-4.8/qfileinfo.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询