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.