PySide – PyQt : How to make set QTableWidget column width as proportion of the available space?

This can be solved by setting the resize-mode for each column. The first section must stretch to take up the available space, whilst the last two sections just resize to their contents:

PyQt5:

header = self.table.horizontalHeader()       
header.setSectionResizeMode(0, QHeaderView.Stretch)
header.setSectionResizeMode(1, QHeaderView.ResizeToContents)
header.setSectionResizeMode(2, QHeaderView.ResizeToContents)

PyQt6/PyQt5:

header = self.table.horizontalHeader()       
header.setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
header.setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)

PyQt4:

header = self.table.horizontalHeader()
header.setResizeMode(0, QHeaderView.Stretch)
header.setResizeMode(1, QHeaderView.ResizeToContents)
header.setResizeMode(2, QHeaderView.ResizeToContents)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)