3

I am trying to auto fit the tableWidget columns to the available area of the tableWidget

Currently my layout looks like the picture below. As can be seen there is unnecessary white space to the right which I would like to fill out evenly between the four columns.

enter image description here

Setting horizontalHeaderStretch to True (shown below) is not what I am after. This stretches the last column unevenly.

enter image description here

I tried to set the sizeAdjustPolicy to AdjustToCOntents but I saw no visible difference.

enter image description here

A similar question can be found here, however I couldn't find any mentions on how to do this directly from the designer.

Any suggestions on how this can be done? Thanks in advance.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
rrz0
  • 2,182
  • 5
  • 30
  • 65

1 Answers1

3

The feature you indicate can not be done with Qt Designer. In Qt Designer, only the Q_PROPERTY enabled by the DESIGNABLE flag can be modified, but setSectionResizeMode() is not a Q_PROPERTY but a method of QHeaderView, that is indicated in the docs:

The DESIGNABLE attribute indicates whether the property should be visible in the property editor of GUI design tool (e.g., Qt Designer). Most properties are DESIGNABLE (default true). Instead of true or false, you can specify a boolean member function.

So you'll have to do it programmatically:

header = self.table.horizontalHeader()       
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
# ...
eyllanesc
  • 235,170
  • 19
  • 170
  • 241