PySide - PyQt : How to make set QTableWidget column width as proportion of the available space?

前端 未结 5 1202
无人及你
无人及你 2020-12-23 22:19

I\'m developing a computer application with PySide and I\'m using the QTableWidget. Let\'s say my table has 3 columns, but the data they contain is very different,

5条回答
  •  醉话见心
    2020-12-23 22:53

    This can be solved by setting the resize-mode for each column. The first section must stretch to take up the available space, whilst the last two sections just resize to their contents:

    PyQt4:

    header = self.table.horizontalHeader()
    header.setResizeMode(0, QtGui.QHeaderView.Stretch)
    header.setResizeMode(1, QtGui.QHeaderView.ResizeToContents)
    header.setResizeMode(2, QtGui.QHeaderView.ResizeToContents)
    

    PyQt5:

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

提交回复
热议问题