如何在PyQt中将表格的宽度和高度设置为布局大小?

时间:2020-05-19 22:54:41

标签: python pyqt pyqt5 pyqt4 qtablewidget

我试图显示表格,使其所有行和列都在布局内。每个单元格的宽度或高度是否太小都无法键入。

这是一段代码,显示了我放置表格的布局以及显示表格的功能。

代码生成如下所示的图像https://pastebin.com/29PjXAds

def createMainBody(self, MainWindow):
        layout = QHBoxLayout()
        self.generalLayout.addLayout(layout, 0, 0)

        layout_mid = QVBoxLayout() # Layout the table is put into
        self.binInfoTable = QTableWidget()
        layout_mid.addWidget(self.binInfoTable)

        layout.addLayout(layout_mid)

        self.displayGraph(arr, color)

def displayGraph(self, graph_array, color_array):
        a = np.array(graph_array) 

        # id, R, G, B
        ca = np.array(color_array)

        * TABLE CSS *

        # Properities of the table
        self.binInfoTable.showGrid()
        self.binInfoTable.setRowCount(len(a))
        self.binInfoTable.setColumnCount(len(a[0]))
        self.binInfoTable.verticalHeader().setVisible(False)
        self.binInfoTable.horizontalHeader().setVisible(False)
        self.binInfoTable.verticalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.binInfoTable.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.binInfoTable.resizeColumnsToContents()

        * CODE TO FILL THE CELLS WITH COLOR *

我有什么

enter image description here

我想要的

enter image description here

0 个答案:

没有答案
相关问题