Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Add column header to TreeView
Forum Updated to NodeBB v4.3 + New Features

Add column header to TreeView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 4 Posters 537 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    ToQdO
    wrote on 16 Jun 2022, 10:49 last edited by
    #1

    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.

    1 Reply Last reply
    1
    • M Offline
      M Offline
      majorRonk
      wrote on 8 Aug 2024, 10:44 last edited by majorRonk 8 Aug 2024, 10:45
      #2

      did anyone find a solution for this?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrecKo
        Qt Champions 2018
        wrote on 8 Aug 2024, 13:40 last edited by
        #3

        Have you tried HorizontalHeaderView?

        1 Reply Last reply
        1
        • C Offline
          C Offline
          csw_control
          wrote on 26 Mar 2025, 02:38 last edited by csw_control
          #4

          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 below

          Item{     // 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
          
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved