Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTableWidget auto stretch last field just like QTreeWidget does

Is there anyway to let QTableWidget's header items stretch to full size just like QTreeWidget does ?

like image 919
daisy Avatar asked May 26 '12 08:05

daisy


1 Answers

From the QTableView documentation:

By default, the cells in a table do not expand to fill the available space.

You can make the cells fill the available space by stretching the last header section. Access the relevant header using horizontalHeader() or verticalHeader() and set the header's stretchLastSection property.

You should give that a try.

 QTableWidget *tw = ...;
 tw->horizontalHeader()->setStretchLastSection(true);

The stretchLastSection documentation has:

Note: The horizontal headers provided by QTreeView are configured with this property set to true, ensuring that the view does not waste any of the space assigned to it for its header.

So that's how the tree views do it.

like image 198
Mat Avatar answered Nov 15 '22 11:11

Mat