Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

python - How to make the size of the last column of QTableWidget equal to the others

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:
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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...