View Full Version : QSplitter and QTableWidget

19th January 2010, 07:38
Hi. I have a QSplitter widget separating two QTableWidget instances.
I want each table to stretch to its area's dimension. Meaning I want the tables to occupy all the space available to them.
How do I achieve that?

table1 = new QTableWidget(splitter);
table2 = new QTableWidget(splitter);

When I pull the handle of the qsplitter, I want the tables to stay stretched to maximum, just like the emails table does in thunderbird.

19th January 2010, 09:07
Add a layout to the QSplitter and then add your 2 tablewidgets to it.

QHBoxLayout* pHNewLayout = new QHBoxLayout(splitter);
pHNewLayout ->addWidget(tablewidget1);
pHNewLayout ->addWidget(tablewidget2);
splitter->setLayout(pHNewLayout );

19th January 2010, 09:25
Add a layout to the QSplitter and then add your 2 tablewidgets to it.

This still doesn't make my two tables to expand to their maximum available space and stay stretched...

19th January 2010, 09:29

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.

To distribute the available space according to the space requirement of each column or row, call the view's resizeColumnsToContents() or resizeRowsToContents() functions.

19th January 2010, 09:40
tsp, thanks, that's exactly what I was looking for.
it's not a matter of not reading the documentation, it's just that I've been looking at this from the wrong angle... I thought it's a matter of layouting...
Thanks a million, this solves my problem.