如何设置QTableView的行高? [英] How to set row height of QTableView?

查看:4329
本文介绍了如何设置QTableView的行高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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,使其对新添加的行使用相同的高度,或者可以向模型发送行的高度?

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?

推荐答案

对于 Qt版本< 5

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

对于 Qt版本> = 5 ,使用

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

如果该功能不适用于垂直标题,则每次添加新行时,您可能都必须调用setRowHeight().

If that function doesn't apply to vertical headers, you likely will have to call setRowHeight() every time you add a new row.

这篇关于如何设置QTableView的行高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆