基于 QML 的 Qt 文件浏览器 [英] Qt File Browser based on QML
本文介绍了基于 QML 的 Qt 文件浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 QFileSystemModel 很容易实现文件浏览器.但是listview UI 并不漂亮.所以我想用QML实现一个文件浏览器.QML 具有模型/视图支持.但是如何在 QML 中显示文件系统树呢?任何线索将不胜感激.
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.
推荐答案
从Qt5.5开始我们有了TreeView
QML组件,
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")));
这篇关于基于 QML 的 Qt 文件浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文