I have TableView with 4 columns. When I enlarge width of main window, I needed enlarge first column width too.
Older way (non QML) was:
QTableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch );
Now I do something like example bellow, but this is not exactly perfect.
QML file: :
TableView {
id: ccPanel
model: ccModel
TableViewColumn {
id: ccName
role: "name"
title: "Name"
width: ccPanel.width - ccSize.width - ccDate.width
}
TableViewColumn {
id: ccSize
role: "size"
title: "Size"
width: 60
}
TableViewColumn {
id: ccDate
role: "Date"
title: "Datum"
width: 85
}
}
Do you know how to help me?
To eliminate strange resizing, make the last column non-resizable manually and use the widthChanged signals of the columns as well as the signal from the TabView. The following code produces a behavior very close to the Qt TableView header.
TableView
{
id: ccPanel
model: ccModel
anchors.fill: parent
onWidthChanged:ccName.width = Math.max(100, ccPanel.width - ccSize.width - ccDate.width)
TableViewColumn
{
id: ccName
role: "name"
title: "Name"
onWidthChanged: ccDate.width = Math.max(60, ccPanel.width - ccSize.width - ccName.width)
}
TableViewColumn
{
id: ccSize
role: "size"
title: "Size"
width: 60
onWidthChanged: ccDate.width = Math.max(85, ccPanel.width - ccSize.width - ccName.width)
}
TableViewColumn
{
resizable: false
id: ccDate
role: "Date"
title: "Datum"
width: 85
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With