gruenkohl
gruenkohl

Reputation: 103

Pyqt: How to maximize the column width in a tableview?

Actually the title contains all information needed. Is there an easy function like tableview.resizeColumnsToContents() that allows the maximization of all column widths within the widget size? My columns are narrow so the table looks very compact.

Upvotes: 8

Views: 5295

Answers (2)

Stephen Terry
Stephen Terry

Reputation: 6279

If you want the columns to expand uniformly, you could also set the resize mode

tableview.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)

In pyqt5 setResizeMode is no longer available. Instead, use setSectionResizeMode and QHeaderView in the QtWidgets module.

Upvotes: 14

Macke
Macke

Reputation: 25680

See resizeColumnsToContents.

There's also a stretchLastSection property that can be used (see QTableView).

Upvotes: 5

Related Questions