Qt File Browser based on QML

亡梦爱人 提交于 2021-02-07 07:21:52

问题


It is easy to implement a file browser by using QFileSystemModel. But the listview UI is not pretty. So I want to implement a file browser using QML. the QML has model/view support. But how to display the filesystem tree in QML? Any clue would be appreciated.


回答1:


Since Qt5.5 we have TreeView QML component available,

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")));



回答2:


I think its kind of late, but still it might help some one.

I recently created QML based filedialog for my project for Symbian using Qt Quick Components. Its implementation is here,

And here is sample application,



来源:https://stackoverflow.com/questions/6133344/qt-file-browser-based-on-qml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!