1

How to stretch the last column of a TableView in qml?

In C++ with Qt framework it is possible to use setStretchLastSection from QHeaderView but is there a way to do it in qml?

EDIT: To be more specific: On the screenshot below, I want the three column to fill the entire width of the TableView, in order to get rid that "ghost" 4th column.

Edit2:

I wanted to do something like that:

TableView{
  model: ListModel{
    ListElement {
      name: "Apple"
      cost: 2.45
    }
    ListElement {
      name: "Orange"
      cost: 3.25
    }
    ListElement {
      name: "Banana"
      cost: 1.95
    }
  }

  TableViewColumn{
    role: "name"
    title: "Name"
  }
  TableViewColumn{
    role: "cost"
    title: "Cost"
  }
  Component.onCompleted: stretchLastSection /*<-----/*
}

But the way to do it for now seems to be by calculating the width of TableViewColumn as @folibis said.

Some related topic with QtDesigner and Qt framework:

QTableView / QTableWidget: Stretch Last Column using Qt Designer

Qt table last column not stretching to fill in parent

How to stretch QTableView last column header

GuillaumeF93
  • 111
  • 1
  • 4
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 03 '22 at 15:16
  • As said above it is hard to answer a question without details, [mcve] etc. Anyway, check the [TableView.columnWidthProvider](https://doc.qt.io/qt-6/qml-qtquick-tableview.html#columnWidthProvider-prop) property that holds a function that returns the widths of columns. You can just calculate that: `TableView.width` - Σ (all columns widths) - the last one. – folibis Sep 04 '22 at 07:52

0 Answers0