12

The columns of my QTableWidget do not fill in the space of the table, so that an empty space is left on the right hand-side. How to make the columns of my QTableWidget assume the maximum space so as to fill in this space?

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
neydroydrec
  • 6,973
  • 9
  • 57
  • 89

2 Answers2

21

The headers of the table have methods for controlling this:

header = table.horizontalHeader()
header.setStretchLastSection(True)

or:

header.setResizeMode(QHeaderView.Stretch)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
0

I don't know of any method to set this property to the QTableWidget's content. However, I could use the following to get the columns to resize:

def resizeEvent(self, event):
    self.setColumnWidth(0, event.size().width())

This resizes the first column only. To resize all columns, one should get all children item and apply column width / number of items.

Mark Skelton
  • 3,663
  • 4
  • 27
  • 47
neydroydrec
  • 6,973
  • 9
  • 57
  • 89