0

I'm attempting something that I thought would be simple, but just cannot find a way to do this. The supplied image demonstrates what I'm after. It's essentially just a QTableWidget with the following behaviour:

  • Fill the available space.
  • A fixed width column on the right.
  • The rest of the columns I'd like to be able to resize manually (so they'd have to stretch proportionally so that all space is filled).

Things I have tried:

  • Setting setStretchLastSection(True). This fills up the space, but you have no control over its width if this is set.
  • Overriding the resizeEvent and calculating and setting everything manually. This seems like a very messy way of doing things, which usually means there's a simpler way.

Is there a simple way of achieving this?

QtableWidget Desired Columns

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Anti-Distinctlyminty
  • 2,615
  • 5
  • 22
  • 24

2 Answers2

0

You can always ResizeToContents all columns with self.my_table.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) and then apply your fixed width to the last one

noEmbryo
  • 2,176
  • 2
  • 10
  • 15
  • As you can see from the documentation [here](https://doc.qt.io/qtforpython/PySide2/QtWidgets/QHeaderView.html#PySide2.QtWidgets.PySide2.QtWidgets.QHeaderView.ResizeMode) setting `QHeaderView.ResizeToContents` means that "The size cannot be changed by the user or programmatically." – Anti-Distinctlyminty Jan 04 '20 at 11:44
0

I managed to get something that works

self.myTable.horizontalHeader().setSectionResizeMode(0, QtWidgets.QHeaderView.Interactive)
self.myTable.horizontalHeader().setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
self.myTable.horizontalHeader().setSectionResizeMode(2, QtWidgets.QHeaderView.Fixed)

The general rule is to set all of the headers to Interactive, the penultimate to Stretch, and final to Fixed.

Anti-Distinctlyminty
  • 2,615
  • 5
  • 22
  • 24