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?
Use QHeaderView.setSectionResizeMode instead of QHeaderView.setResizeMode:
Use setSectionResizeMode instead.
(Quote from documentation for QHeaderView.setResizeMode)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With