How to set row height of QTableView?

萝らか妹 提交于 2019-12-20 08:59:14

问题


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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/19304653/how-to-set-row-height-of-qtableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!