I wanted to make a table that the size (width and height) of items inside the list to be equal. But the width of the last column is not the same as the others (it has been stretched)
I've used the setFixedSize to change the size, maybe that's the problem.
See this picture:
This is my code:
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QHeaderView, QTableWidget, QWidget
# Main Window
class App(QWidget):
def __init__(self):
super().__init__()
self.title = "PyQt5 - QTableWidget"
self.left = 200
self.top = 100
self.width = 740
self.height = 880
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.createTable()
def createTable(self):
self.tableWidget = QTableWidget(self)
self.tableWidget.setRowCount(8)
self.tableWidget.setColumnCount(8)
self.tableWidget.setFixedSize(700, 700)
self.tableWidget.move(100, 100)
self.tableWidget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.tableWidget.horizontalHeader().setStretchLastSection(True)
self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.tableWidget.verticalHeader().setStretchLastSection(True)
self.tableWidget.verticalHeader().setSectionResizeMode(QHeaderView.Stretch)
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = App()
ex.show()
sys.exit(app.exec_())
How can I fix it?
question from:
https://stackoverflow.com/questions/65853923/how-to-make-the-size-of-the-last-column-of-qtablewidget-equal-to-the-others 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…