Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.8.0, 5.9.1
-
All platforms/environments.
-
10b3bffbd21b6265a3d124f310c99fcbac2b027f (qt/qtquickcontrols/5.12)
Description
When a column is dynamically added to a TableView (as opposed to having them statically defined in the TableView itself) using resizeColumnsToContents doesn't behave as expected. This appears to be because its implementation uses __columns.length to determine the number of columns in the TableView, when it should probably be using columnCount, i.e. its implementation should be as follows:
function resizeColumnsToContents () { - for (var i = 0; i < __columns.length; ++i) { + for (var i = 0; i < columnCount; ++i) { var col = getColumn(i) var header = __listView.headerItem.headerRepeater.itemAt(i) if (col) { col.__index = i col.resizeToContents() if (col.width < header.implicitWidth) col.width = header.implicitWidth } } }
__columns.length doesn't appear to change when columns are added to the TableView, and in fact it seems to be wrong anyway, with an empty TableView:
import QtQuick 2.5 import QtQuick.Controls 1.4 Item { Component { id: columnComponent TableViewColumn {} } TableView { id: tableView } Component.onCompleted: { console.log("before " + tableView.__columns.length + " " + tableView.columnCount); tableView.addColumn(columnComponent.createObject(tableView)); tableView.addColumn(columnComponent.createObject(tableView)); tableView.addColumn(columnComponent.createObject(tableView)); console.log("after " + tableView.__columns.length + " " + tableView.columnCount); } }
...this prints:
sdks/Qt5.8.0/5.8/gcc_64/bin/qmlscene test.qml qml: before 1 0 qml: after 1 3
At no point does the TableView have one column.