How to make QTableWidget's columns assume the maximum space?

那年仲夏 提交于 2019-12-01 15:26:13

The headers of the table have methods for controlling this:

header = table.horizontalHeader()
header.setStretchLastSection(True)

or:

header.setResizeMode(QHeaderView.Stretch)
Benjamin

I don't know of any method to set this property to the QTableWidget's content. However, I could use the following to get the columns to resize:

def resizeEvent(self, event):
    self.setColumnWidth(0, event.size().width())

This resizes the first column only. To resize all columns, one should get all children item and apply column width / number of items.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!