Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt4 code not working on PyQt5 (QHeaderView)

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?

like image 916
Rictrunks Avatar asked Oct 01 '14 12:10

Rictrunks


Video Answer


2 Answers

Use QHeaderView.setSectionResizeMode instead of QHeaderView.setResizeMode:

Use setSectionResizeMode instead.

(Quote from documentation for QHeaderView.setResizeMode)

like image 89
Ramchandra Apte Avatar answered Oct 28 '22 11:10

Ramchandra Apte


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)
like image 27
Xavi Martínez Avatar answered Oct 28 '22 11:10

Xavi Martínez