使用QFileSystemModel很容易实现文件浏览器。但列表视图的 UI 并不漂亮。所以我想用QML实现一个文件浏览器。 QML 具有模型/视图支持。但是如何在 QML 中显示文件系统树呢?任何线索将不胜感激。
从 Qt5.5 开始我们有TreeView
QML 组件可用,
main.qml
:
import QtQuick.Controls 1.4
TreeView {
anchors.fill: parent
TableViewColumn {
title: "Name"
role: "fileName"
width: 300
}
model: my_model
}
main.cpp
:
QFileSystemModel model;
model.setRootPath("/");
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("my_model", &model);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)