How to set row height of QTableView?
48,418
For Qt versions < 5
QHeaderView *verticalHeader = myTableView->verticalHeader();
verticalHeader->setResizeMode(QHeaderView::Fixed);
verticalHeader->setDefaultSectionSize(24);
For Qt versions >= 5 use
QHeaderView *verticalHeader = myTableView->verticalHeader();
verticalHeader->setSectionResizeMode(QHeaderView::Fixed);
verticalHeader->setDefaultSectionSize(24);
If that function doesn't apply to vertical headers, you likely will have to call setRowHeight()
every time you add a new row.
![Ashot](https://i.stack.imgur.com/har6o.jpg?s=256&g=1)
Author by
Ashot
Updated on July 09, 2022Comments
-
Ashot almost 2 years
I have
QTableView
andQAbstractTableModel
. I require rows to have height equal to 24. I know the only way to do this is by callingQTableView::setRowHeight
. Since the model is dynamic it may be added new rows, but I don't want to callsetRowHeight
each time new row is added.How can I configure
QTableView
such that it uses the same height for new added rows or can a model be sent the height of rows? -
Llopeth almost 5 yearsI think it's better to give a name to the pointer different from the function name, otherwise you may have name conficts, e.g. if you do this from QTableView constructor QHeaderView *vh = myTableView->verticalHeader();
-
Cory Klein over 4 yearsIf
verticalHeader
is already in scope, then just callsetResizeMode
andsetDefaultSectionSize
on it directly, no need to be worried about variable shadowing and no need to copy a local pointer. -
MattBas almost 4 years
QHeaderView
bounds the value passed tosetDefaultSectionSize
so you might need to callsetMinimumSectionSize
andsetMaximumSectionSize
before setting the default size.