如何设置QTableView的行高?

时间:2020-12-18 19:41:27

I have QTableView and QAbstractTableModel. I require rows to have height equal to 24. I know the only way to do this is by calling QTableView::setRowHeight. Since the model is dynamic it may be added new rows, but I don't want to call setRowHeight each time new row is added.

我有QTableView和QAbstractTableModel。我要求行的高度等于24.我知道唯一的方法是调用QTableView :: setRowHeight。由于模型是动态的,因此可能会添加新行,但每次添加新行时我都不想调用setRowHeight。

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?

如何配置QTableView使其对新添加的行使用相同的高度,或者可以将模型发送到行的高度?

1 个解决方案

#1


57  

For Qt versions < 5

对于Qt版本<5

QHeaderView *verticalHeader = myTableView->verticalHeader();
verticalHeader->setResizeMode(QHeaderView::Fixed);
verticalHeader->setDefaultSectionSize(24);

For Qt versions >= 5 use

对于Qt版本> = 5使用

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.

如果该函数不适用于垂直标题,则每次添加新行时都可能需要调用setRowHeight()。

#1


57  

For Qt versions < 5

对于Qt版本<5

QHeaderView *verticalHeader = myTableView->verticalHeader();
verticalHeader->setResizeMode(QHeaderView::Fixed);
verticalHeader->setDefaultSectionSize(24);

For Qt versions >= 5 use

对于Qt版本> = 5使用

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.

如果该函数不适用于垂直标题,则每次添加新行时都可能需要调用setRowHeight()。