Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QtQuick.TableView stretch columns to fit contents



  • What is the proper way to have a QtQuick.TableView stretch certain columns to fill the width of the table as with QHeaderView::Stretch? contentWidth: width seems to disable horizontal scrolling, but it won't stretch the table to fit the width.

    The documentation for TableView.contentWidthProvider says that returning negative number will have the column fall back on the delegate for column widths. This is incorrect, as the code prohibits and complains when a negative number is returned:

    QML TableView: columnWidthProvider did not return a valid width for column: 2

    But even if TableView.contentWidthProvider did work, it would not stretch the table to fill the full with.



  • @patrickkidd said in QtQuick.TableView stretch columns to fit contents:

    What is the proper way to have a QtQuick.TableView stretch certain columns to fill the width of the table as with QHeaderView::Stretch? contentWidth: width seems to disable horizontal scrolling, but it won't stretch the table to fit the width.

    The documentation for TableView.contentWidthProvider says that returning negative number will have the column fall back on the delegate for column widths. This is incorrect, as the code prohibits and complains when a negative number is returned:

    QML TableView: columnWidthProvider did not return a valid width for column: 2

    But even if TableView.contentWidthProvider did work, it would not stretch the table to fill the full with.

    I managed to implement a column stretch by manually calculating each column width after every change to the TableView width, calling forceLayout() after every onWidthChanged. It looks like this is the only way to do this until the official table header type is added in a Qt update.


Log in to reply