Home > Net >  Add column header to TreeView in Qt QML
Add column header to TreeView in Qt QML

Time:06-22

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.

TreeView now (without headers)

CodePudding user response:

According to the documentation headers for TreeViews are not supported by QML.

  • Related