9

I was using PyQt4 and this code works great.

self.table.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)

It's stretching a column in a table. But when I run the code with PyQt5, I'm getting this error:

Attribute Error: 'QHeaderView' object has no attribute 'setResizeMode'

Can you please help? Or simply; how can I strect any column in PyQt5?

2 Answers 2

15

Use QHeaderView.setSectionResizeMode instead of QHeaderView.setResizeMode:

Use setSectionResizeMode instead.

(Quote from documentation for QHeaderView.setResizeMode)

10

In PyQt5 should be:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.