Home:ALL Converter>QTableView / QTableWidget: Stretch Last Column

QTableView / QTableWidget: Stretch Last Column

Ask Time:2022-09-02T21:46:02         Author:GuillaumeF93

Json Formatter

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

Author:GuillaumeF93,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/73583548/qtableview-qtablewidget-stretch-last-column
yy