I've got a simple QTableView and I essentially want to emulate this:
view.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
However, I cannot actually use this, since this calls sizeHint
on every single row, which is unacceptable in my case, since the widget needs to be responsive on startup and the calculations take a long time for all the rows. Therefore this is not an option.
I know what the size of a single column, which is always the same, and is always the one with largest height. However, the width of this cell may not always be the widest of all the cells in a row. I've made those cells the correct size by doing this, but this obviously makes all the cells the same size, and many are now far too wide.
view.horizontalHeader().setDefaultSectionSize(200)
view.verticalHeader().setDefaultSectionSize(100)
I've also tried to set individual column widths, but that seems to have no effect at all on the widths, like this:
view.setColumnWidth(0, 5)
Also, setting individual column widths isn't that great, since I can't know in advance how wide they're going to be.
Is there any way to use (or emulate) the ResizeToContents
approach (as shown above), but in a way that wouldn't require checking all the cell sizes?