#include <QtWidgets/QApplication>
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTreeView treeView;
QFileSystemModel model(NULL);
model.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); //忽略文件夹
model.setRootPath(QDir::currentPath());
//设置显示的文件格式
QStringList filter;
filter << "*.fbx" << "*.abc" << "*.obj";
model.setNameFilters(filter);
model.setNameFilterDisables(false);
treeView.setSortingEnabled(true); // 直接加上这个就可以排序了;
treeView.setModel(&model);
//获得选中的文件
QModelIndex index = treeView.currentIndex();
QFileInfo fileinfo = treeView.fileInfo(index);
const QAbstractItemModel* lModel = index.model();
if (lModel)
{
QString file_name = fileinfo.fileName(); // 文件名
QString file_suffix = fileinfo.suffix();//文件后缀
QString file_path = fileinfo.absolutePath(); //绝对路径
}
treeView.setRootIndex(model.index("C:/")); //设置root path
treeView.show();
return a.exec();
}
c++中QTreeView的使用
最新推荐文章于 2024-05-17 05:54:40 发布