Directory View using Treeview and Folderlistmodel
-
wrote on 14 Apr 2023, 08:52 last edited by tuno
I want to create Directory view which use treeview for structure and folderlistmodel to fetch folderslist. It contains dropdown button when click it shows list of corresponding subfolders in treeviews child. But don't know how to add subfolders to child of treeview.
Im using Qt 5.15.2
My code for folderview.qml is here
import QtQuick 2.15 import QtQuick.Layouts 1.15 import QtQuick.Controls 1.4 import QtQuick.Controls.Styles 1.4 import Qt.labs.folderlistmodel 2.1 import QtQuick.Studio.Components 1.0 Item { width: 500 height: 416 TreeView { id: treeView width: parent.width height: parent.height frameVisible: false headerVisible: false backgroundVisible: false style: TreeViewStyle { itemDelegate: Component { Item { CFolderExpBtn { id: dropdown anchors.left: parent.left anchors.leftMargin: -15 anchors.verticalCenter: parent.verticalCenter checkable: true scale: 0.6 //visible: model.hasChildren(styleData.parent) } SvgPathItem { id: icon y: -7 width: 40 height: 40 anchors.leftMargin: -10 anchors.left: dropdown.right fillColor: "#ffe705" path: "M 8.5 8 C 6.019 8 4 10.019 4 12.5 L 4 18 L 16.052734 18 C 16.636734 18 17.202344 17.793922 17.652344 17.419922 L 23.5 12.546875 L 19.572266 9.2734375 C 18.586266 8.4524375 17.336734 8 16.052734 8 L 8.5 8 z M 27.644531 13 L 19.572266 19.724609 C 18.585266 20.546609 17.336734 21 16.052734 21 L 4 21 L 4 35.5 C 4 37.981 6.019 40 8.5 40 L 39.5 40 C 41.981 40 44 37.981 44 35.5 L 44 17.5 C 44 15.019 41.981 13 39.5 13 L 27.644531 13 z" scale: 0.50 strokeWidth: -1 } Label { anchors.left: icon.right anchors.leftMargin: 5 anchors.verticalCenter: parent.verticalCenter font.family: "Montserrat" color: "#ffffff" font.pointSize: 9 elide: styleData.elideMode text: styleData.value // MouseArea{ // onClicked: // } } } } rowDelegate: Component { Rectangle { color: styleData.selected ? "#303030" : "#202020" height: 30 } } } FolderListModel { id: folderModel showFiles: false folder: "file:///C:" nameFilters: ["*"] showDirs: true } model: folderModel TableViewColumn { id: tableViewColumn title: "Directory" role: "fileName" width: 298 movable: false resizable: false } } }
Please help me with this.
Thank you
1/1