Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

New TableView - dynamic columns possible?



  • 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


Log in to reply