自定义 QTableWidget 类的内容缩小到非常小的尺寸

问题描述

我在 Pyqt5 中创建了一个派生 QTableWidget 类的类,这样做之后我厌倦了显示内容(加载时的静态内容和之后的动态内容),但表格大小不适合父框架的大小。 (PS:做 setFixedHeight/Width 工作,但它不会在调整父级时调整大小)

    def __init__(self,parent:QTableView):
        super(STable,self).__init__(parent)

    def init_table(self,row=1,cols=0,headers=None):
        if headers is None:
            headers = []
        self.setAlternatingRowColors(True)
        self.setColumnCount(cols)
        self.setRowCount(row)
        self.setFixedWidth(self.parent().width())
        self.setFixedHeight(self.parent().height())
        self.setHorizontalHeaderLabels(headers)
        print(self.parentWidget().geometry())
        print(self.parentWidget().objectName())
        # both print statement print the geometry as 0,100,30 and name as the correct parent's name
        # geometry is wrong as the parent frame is occupying 800x800
        # doesn't work
        self.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)