Reputation: 189686
How do you change the default row size in a QTableView so it is smaller? I can call resizeRowsToContents()
, but then subsequent inserts still add new rows at the end which are the default size.
I am guessing it might have something to do with style sheets but I'm not familiar enough with what things impact the visual changes.
I am using PySide in Python, but I think this is a general Qt question.
example view:
default table appearance
what the table looks like after resizeRowsToContents()
:
now if I add a new blank row at the end:
Darn, it uses the default row height, with all that extra space.
Upvotes: 6
Views: 14462
Reputation: 18504
Qt::SizeHintRole
responsible for width and height of cell. So you can just:
someModel.setData(someIndex,QSize(width, height), Qt::SizeHintRole);
Or just this:
someView.verticalHeader().setDefaultSectionSize(10);
And I think that setDefaultSectionSize
is exactly what are you looking for. AFAIK there is no another simple way.
defaultSectionSize : int
This property holds the default size of the header sections before resizing. This property only affects sections that have Interactive or Fixed as their resize mode.
If you don't know how much pixels you need, then try to get this height after applying resizeRowsToContents()
with rowHeight()
So it should be something like:
resizeRowsToContents();
someView.verticalHeader().setDefaultSectionSize(someView.rowHeight(0));
Upvotes: 14