PDA

View Full Version : QSplitter and QTableWidget



vanwil
19th January 2010, 08: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);
splitter->addWidget(table1);
splitter->addWidget(table2);

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.

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


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

vanwil
19th January 2010, 10: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...

tsp
19th January 2010, 10:29
http://doc.qt.nokia.com/4.6/qtableview.html


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.

vanwil
19th January 2010, 10: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.