C++ 如何设置QTableView的行高?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19304653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set row height of QTableView?
提问by Ashot
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
以便它对新添加的行使用相同的高度,或者可以向模型发送行的高度?
回答by Cory Klein
For Qt versions < 5
对于Qt 版本 < 5
QHeaderView *verticalHeader = myTableView->verticalHeader();
verticalHeader->setResizeMode(QHeaderView::Fixed);
verticalHeader->setDefaultSectionSize(24);
For Qt versions >= 5use
对于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()
每次添加新行时可能都必须调用。