Solved Changing TableView columnWidthProvider from 0 (hidden) to non-zero
-
I have a
TableView
inside myWindow
. I am usingcolumnWidthProvider
to provide the column width to be a specific size, and I am callingonWidthChanged: forceLayout()
to force updates afterwidth
changes. However if the initial value returned bycolumnWidthProvider
is zero (meaning tellingTableView
to hide that column) then the update does not have any effect. Is this a bug inTableView
? If not how can I circumvent this issue? I think if not a bug, this would be incompatible with design of other QtQuick components such as for example the Window that has theTreeView
inside, since it first creates itscontentItem
at size 0x0 and then resizes it to the final Window size. Therefore theTableView
would only behave properly if I set a fake initial size for it if used inside aWindow
(which I prefer not to do).Example code:
import QtQuick 2.15 import QtQuick.Window 2.15 import Qt.labs.qmlmodels 1.0 Window { width: 400 height: 400 visible: true TableView { anchors.fill: parent columnSpacing: 1 rowSpacing: 1 boundsBehavior: Flickable.StopAtBounds /* does not resize and have the column appear */ columnWidthProvider: function (column) { return column === 0 ? width : 0 } onWidthChanged: forceLayout() /**********************************************/ model: TableModel { TableModelColumn { display: "checked" } TableModelColumn { display: "amount" } TableModelColumn { display: "fruitType" } TableModelColumn { display: "fruitName" } TableModelColumn { display: "fruitPrice" } // Each row is one type of fruit that can be ordered rows: [ { // Each property is one cell/column. checked: false, amount: 1, fruitType: "Apple", fruitName: "Granny Smith", fruitPrice: 1.50 }, { checked: true, amount: 4, fruitType: "Orange", fruitName: "Navel", fruitPrice: 2.50 }, { checked: false, amount: 1, fruitType: "Banana", fruitName: "Cavendish", fruitPrice: 3.50 } ] } delegate: TextInput { text: model.display padding: 12 selectByMouse: true onAccepted: model.display = text Rectangle { anchors.fill: parent color: "#efefef" z: -1 } } } }
-
Turns out it was a bug:
https://bugreports.qt.io/browse/QTBUG-92076 -
This post is deleted! -
Turns out it was a bug:
https://bugreports.qt.io/browse/QTBUG-92076