Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QtQuick.TableView stretch columns to fit contents
Qt 6.11 is out! See what's new in the release blog

QtQuick.TableView stretch columns to fit contents

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by
    #1

    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.

    https://alaskafamilysystems.com/

    P 1 Reply Last reply
    0
    • P patrickkidd

      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.

      P Offline
      P Offline
      patrickkidd
      wrote on last edited by
      #2

      @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.

      https://alaskafamilysystems.com/

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tobias Fensch
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved