Add column header to TreeView
Unsolved
QML and Qt Quick
-
I want to add headers for columns in my TreeView. Is there a way to do it in Qt6.3?
Currently, my qml looks like this:TreeView { id: tree_view anchors{ fill: parent margins: 10 } model: FileSystemModel clip: true delegate: TreeViewDelegate { contentItem: Text { anchors.leftMargin: leftMargin anchors.rightMargin: rightMargin text: { if (column === 0) file_name else if (column === 1) inner_files else file_size } } } }
I cant use TableViewColumn because the compiler says that "it's not a type". I have already switched to Qt 6.3 from the 6.2 version, because of the same problem with the TreeView component.
-
Have you tried HorizontalHeaderView?
-
I think this is solved. GrecKo's suggestion is works well.
you can start from the example 'QT Quick Controls - table of contents'.
modify Main.qml like belowItem{ // added component anchors.fill: parent HorizontalHeaderView { // added component id: horizontalHeader anchors.top: parent.top anchors.left: treeView.left syncView: treeView model: ["title", "content"] clip: true } TreeView { id: treeView //anchors.fill: parent // anchoring is modified anchors.top: horizontalHeader.bottom anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom anchors.margins: 10 clip: true