5

使用 QFileSystemModel 很容易实现文件浏览器。但是listview UI 并不漂亮。所以我想用QML实现一个文件浏览器。QML 具有模型/视图支持。但是如何在 QML 中显示文件系统树呢?任何线索将不胜感激。

4

2 回答 2

5

从 Qt5.5 开始,我们有TreeViewQML 组件可用,

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")));
于 2015-10-12T09:18:13.753 回答
2

我认为它有点晚了,但它仍然可能对某些人有所帮助。

我最近使用 Qt Quick Components 为我的 Symbian 项目创建了基于 QML 的文件对话框。它的实现在这里

是示例应用程序

于 2012-02-16T02:17:28.307 回答