qml filesystemmodel改变路径
时间: 2023-06-11 14:07:55 浏览: 62
要改变 QML FileSystemModel 的路径,可以通过设置其 rootPath 属性来实现。以下是一个简单的例子:
```qml
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.0
import Qt.labs.folderlistmodel 2.1
Window {
visible: true
width: 640
height: 480
FolderListModel {
id: folderModel
nameFilters: ["*.qml"]
rootPath: "/home/user/documents"
}
ListView {
anchors.fill: parent
model: folderModel
delegate: Text {
text: fileName
}
}
Button {
text: "Change Path"
onClicked: {
folderModel.rootPath = "/home/user/pictures"
}
}
}
```
在这个例子中,我们创建了一个 FolderListModel,设置了其 rootPath 属性为 "/home/user/documents",这个模型被用于在 ListView 中显示文件名。当点击按钮时,我们改变了 rootPath 属性为 "/home/user/pictures",这个模型会自动重新加载以显示新的路径下的文件。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)