Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. New TableView - dynamic columns possible?
Forum Update on Monday, May 27th 2025

New TableView - dynamic columns possible?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 154 Views
  • 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.
  • SeDiS Offline
    SeDiS Offline
    SeDi
    wrote on last edited by
    #1

    Hi,
    I still use the (now deprecated) QtQuick.Controls 1.4 for TableView in order to achieve dynamic columns. For this I am taking the resources approach (see below), but it seems impossible in the new TableView. For starters, TableViewColumn doesn't seem to exist.

    Any idea on how to achieve that? Or is it better to stick with the old TableView for now?

    TableView {
             id: dynTable
            model: sceneLoader ? sceneLoader.loaderModel : 0
            resources:
            {
                var temp = []
                var columnComponent
                for(var i=0; i<roleList.length; i++) {
                    var role  = roleList[i]
                    var columnHeaderName = //whatever
                            columnComponent = columnComponentText
                    if (columnComponent) {
                        temp.push(columnComponent.createObject(
                                      dynTable, {
                                          "role": role,
                                          "title": columnHeaderName,
                                          "width": //whatever
                                          "visible": true
                                      }))
                    }
                    
                }
                
                return temp
            }
    

    As for the Component:

    Component {
            id: columnComponentText
            
            TableViewColumn { 
                delegate: Item {
                    clip: true
                    Rectangle {
                        id: backColorRect
                        // whatever
                    }
                    Text {
                        id: textDelegate
                        anchors.fill: parent
                        text: //whatever
                        clip: true
                    }
                }
            }
        }
    

    In the new (Qt 5.13) TableView

    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