When you have created a table using pyqt, you may find this table will have a default width. However, this width can not changed when resizing window. To fix this problem, we will tell you how to do in this tutorial.
For example, the table with default width likes:
When resizing widow, you may find the width of table is not changed.
What is table adaptive width?
It means the width of table is changed when resizing window.
How to set pyqt table adaptive width?
It is very simple in pyqt5. Here is an example.
First, import some libraries.
from PyQt5.QtWidgets import QTableWidget,QTableWidgetItem, QHeaderView
Set adaptive width for table
hheader = table.horizontalHeader() hheader.setSectionResizeMode(QHeaderView.Stretch)
Where table is QTableWidget object. Run this code, you will find the effect:
Goodness me, I took my time finding this. Perfect thank you!!