Qt 6.5: QML TableView lose resizing ability when using columnWidthProvider
-
In Qt 6.5 TableView, the ability to resize rows is very welcome as it was something that was available in the old QtQuick.Controls 1. But I have noticed that when using columnWidthProvider
columnWidthProvider: function(column) { if(columnsModel.at(column).visible) return table.view.columnWidth(column) return 0 }
Make it that the rows are not resizable anymore because columnWidthProvider is invoke every time I drag the cell to resize it, so the size is always reseted to the value returned by columnWidthProvider.
Am I doing something wrong or is there a way to overcome this issue?
-
I know it's an old post but if anyone is looking for the solution. I faced the same problem. column width provider enforces the width and blocks the resize option. The workaround for this is to create a function for columnwidthprovider and set the width of the delegates directly using the function
-
some tips for this.
ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("HeaderView") TableModel { id: qmlTabModel TableModelColumn { display: "name" } TableModelColumn { display: "color" } TableModelColumn { display: "age" } rows: [ { "name": "cat", "color": "black", "age": "1.1" }, { "name": "dog", "color": "brown", "age": "1.2" }, { "name": "bird", "color": "white", "age": "1.3" } ] } Rectangle { id: bgtab anchors.fill: parent color: Qt.styleHints.appearance === Qt.Light ? palette.mid : palette.midlight onWidthChanged: { tableView.forceLayout() } HorizontalHeaderView { id: horizontalHeader anchors.left: tableView.left anchors.right: parent.right; anchors.top: parent.top syncView: tableView clip: true model: qmlTabModel delegate: Label { text: qmlTabModel.columns[column].display } } VerticalHeaderView { id: verticalHeader anchors.top: tableView.top anchors.left: parent.left syncView: tableView clip: true } TableView { id: tableView anchors.left: verticalHeader.right anchors.top: horizontalHeader.bottom anchors.bottom: parent.bottom contentWidth: parent.width; columnSpacing: 1 rowSpacing: 1 boundsBehavior: Flickable.StopAtBounds property var columnWidths: [100, 50, bgtab.width] columnWidthProvider: function(column) { let w = explicitColumnWidth(column) if (w >= 0 && column !== (columns - 1)) { columnWidths[column] = w; return w; } if (column === (columns - 1)) { w = columnWidths[column]; let i = columns - 1; while(--i !== -1) w -= columnWidths[i]; return w; } return columnWidths[column]; } model: qmlTabModel delegate: Rectangle { implicitHeight: 20 color: palette.base Label { text: display } } } } }