As per the documentation I should be able to force it to only use the displayed rows by calling setResizeContentsPrecision(0), but that doesnt take the pressure off things... I will look into how much it actually accesses.
And I was sloppy in my previous post: I am not using a QTableWidget but indeed a QTableView with my own model.
For the model, you would need to implement Qt::SizeHintRole
I think it should be possible to find a constant one-fits-all value of line-height here. I dont mind wasting a few pixels here and there, but the default height is like 2x of a reasonable size.
For example, in practice and on my system this does nicely:
table
->verticalHeader
()->setSectionResizeMode
(QHeaderView::Fixed);
table
->verticalHeader
()->setDefaultSectionSize
(QFontMetrics(table
->font
()).
lineSpacing() + 4);
table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
table->verticalHeader()->setDefaultSectionSize(QFontMetrics(table->font()).lineSpacing() + 4);
To copy to clipboard, switch view to plain text mode
The +4 basically ensure there's enough space so the last pixels dont get cut off. But it bothers me a bit to hardcode such arbitrary values, when the final result depends on Fonts and Styles.
Bookmarks