Important: Please read the Qt Code of Conduct -

qml 5.12 TableView columnt width depending on content?

  • Hi!
    I'm wondering, is there any way to adopt width of the columnt to the content?
    I got so far, that

    TableView {
                id: table
                Layout.alignment: Qt.AlignCenter
                Layout.preferredWidth : 800
                Layout.preferredHeight: 300
                columnWidthProvider: function (column) { return 100 }
                rowHeightProvider  : function (row)    { return 100 }
                clip: true
                model: StandardModel {}
                delegate: Rectangle {
                    border.color: "blue"
                    border.width: 1
                    color: (heading==true) ? "red" : "green"
                    Text {
                        id: text
                        text: tabledata
                        font.pointSize: 12
                        anchors.centerIn: parent

    Suppose, that i could calc width of the Text (there is a function named contentWidth ). Should i try to iterate over rows in columnWidthProvider to calc the maximum value of the cells in the column and returnin this? (i dont get how to iterate over rows in column)

    Here is an example of my table (but its obvious that columns should be different width which known only runtime)

Log in to reply