1

I am a beginner to Qt and PyQt, and would like to resize a table's width so that is shows each column in full.

Here is my current code that just shows a test label and the table in question:

tableHeaders = ["Title","Artist","Spotify","YouTube","Local"]

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        label = QLabel("Test")
        table = QTableWidget(4, 5)
        table.setHorizontalHeaderLabels(tableHeaders)
        for x, track in enumerate(tracks):
            for y, cell in enumerate(track):
                table.setItem(x,y,QTableWidgetItem(cell))
        grid = QGridLayout()
        grid.setSpacing(10)

        grid.addWidget(label,0,0)
        grid.addWidget(table,0,1)
        self.setLayout(grid)
        self.setWindowTitle("TableTest")
        self.show()

This creates a table of the default width and height. I know I can resize the table manually by specifying a pixel count, but how do you resize the table so all the columns are shown in full, regardless of their contents? sizeHint just seems to return the default table size.

  • I think this was incorrectly marked as a duplicate. The linked answer addresses resizing columns based on contents. The question was about resizing REGARDLESS of the contents. – J Webster Jul 09 '18 at 15:49
  • 1
    The duplicate was what I wanted, I'm just bad at explaining things. – theParanoidAndroid Jul 09 '18 at 15:51

0 Answers0