2024-09-21 00:56:15 发布
网友
如何更改QTableView中的默认行大小以使其更小?我可以调用resizeRowsToContents(),但随后的插入仍会在末尾添加默认大小的新行。
resizeRowsToContents()
我猜这可能与样式表有关,但我对影响视觉变化的因素还不够熟悉。
我在Python中使用PySide,但我认为这是一个一般的Qt问题。
示例视图:
默认表外观
表在resizeRowsToContents()之后的外观:
现在,如果我在末尾添加一个新的空行:
该死,它使用默认的行高和所有额外的空间。
Qt::SizeHintRole负责单元格的宽度和高度。所以你可以:
Qt::SizeHintRole
someModel.setData(someIndex,QSize(width, height), Qt::SizeHintRole);
或者只是这个:
someView.verticalHeader().setDefaultSectionSize(10);
我认为setDefaultSectionSize正是你想要的。恐怕没有其他简单的方法了。
setDefaultSectionSize
From doc:
defaultSectionSize : intThis property holds the default size of the header sections before resizing. This property only affects sections that have Interactive or Fixed as their resize mode.
defaultSectionSize : int
This property holds the default size of the header sections before resizing. This property only affects sections that have Interactive or Fixed as their resize mode.
如果您不知道需要多少像素,那么在使用rowHeight()应用resizeRowsToContents()之后,尝试获取此高度
rowHeight()
所以应该是这样的:
resizeRowsToContents(); someView.verticalHeader().setDefaultSectionSize(someView.rowHeight(0));
Qt::SizeHintRole
负责单元格的宽度和高度。所以你可以:或者只是这个:
我认为
setDefaultSectionSize
正是你想要的。恐怕没有其他简单的方法了。From doc:
如果您不知道需要多少像素,那么在使用
rowHeight()
应用resizeRowsToContents()
之后,尝试获取此高度所以应该是这样的:
相关问题 更多 >
编程相关推荐