Qt Designer直接从设计自动调整tableWidget

2024-09-29 23:23:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将tableWidget列自动调整到tableWidget的可用区域

目前我的布局如下图所示。可以看出,右边没有多余的空白,我想在四列之间均匀地填充

enter image description here

horizontalHeaderStretch设置为True(如下所示)不是我想要的。这会不均匀地拉伸最后一列

enter image description here

我试着将sizeAdjustPolicy设置为AdjustToCOntents,但没有看到明显的区别

enter image description here

类似的问题可以在here中找到,但是我找不到任何关于如何直接从设计师那里做到这一点的内容

对如何做到这一点有什么建议吗?提前谢谢


Tags: true区域内容here布局建议空白区别
1条回答
网友
1楼 · 发布于 2024-09-29 23:23:51

您指定的功能无法使用Qt Designer完成。在Qt Designer中,只能修改可设计标志启用的Q\u属性,但是setSectionResizeMode()不是Q\u属性,而是QHeaderView的方法,在docs中指出:

The DESIGNABLE attribute indicates whether the property should be visible in the property editor of GUI design tool (e.g., Qt Designer). Most properties are DESIGNABLE (default true). Instead of true or false, you can specify a boolean member function.

因此,您必须以编程方式进行:

header = self.table.horizontalHeader()       
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
# ...

相关问题 更多 >

    热门问题