[Interest] QTableView Column Width and Headers

Volker Hilsheimer volker.hilsheimer at qt.io
Wed May 29 16:53:17 CEST 2024



On 24 May 2024, at 20:39, Michael Jackson <mike.jackson at bluequartz.net> wrote:

I have a question about how the column widths of a QTableView are calculated? How can I have the QTableView set the column with “to contents” that includes the QHeader also? For example I have a QHeaderView with the first “section” that has text “This is a really really really long header”, but the actual data that is in the QTableView under that header are short values such as “100” or “2” or “1.231”. When the QTableView is rendered the the column with is only as wide as the QTableView. It is like the QHeaderView is not taken into account when calculating the width of the column.

This is with Qt 6.5.3 and 6.6.3.

--
Mike Jackson


Hi Mike,

you should be able to reimplement https://doc.qt.io/qt-6/qtableview.html#sizeHintForColumn and https://doc.qt.io/qt-6/qtableview.html#sizeHintForRow to take the https://doc.qt.io/qt-6/qheaderview.html#sectionSizeHint into account.

Cheers,
Volker


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240529/14b9079e/attachment.htm>


More information about the Interest mailing list