pyqt5 change table widget column width 1

pyqt5 change table widget column width

header = self.table.horizontalHeader()       
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
#the first column will stretch to fill the window and the others will resize 
#to the contents. If you want them to be equally sized change all resize modes
#to QtWidgets.QHeaderView.Stretch

Here is what the above code is Doing:
1. We get the horizontal header of the table.
2. We set the resize mode of the first column to stretch.
3. We set the resize mode of the second and third columns to resize to contents.

Similar Posts