PDA

View Full Version : adjust the size of the columns in a QTableWidget



franco.amato
2nd February 2011, 23:07
Hi to all,
I'm using a QTableWidget to write some log of my application.
The widget has 2 columns ( 1º column = some text(with a small icon), 2º column = the date & time ).
I would adjust the width of the columns so that the first colums take the 75% of the widget and the second colums take the rest.
I tried setting the column span but seems not what I need.
How can I do?
Best Regards,
Franco

Added after 4 minutes:

I found and tried the

tableWidget->horizontalHeader()->setStretchLastSection( true );method. It expands the columns but at reverse. Colums 1 take 25% of the widget and column 2 the rest.
I would do the reverse,
thanx

ChrisW67
2nd February 2011, 23:34
I think you could create your own QHeaderView derivative that uses its resizeEvent() handler to set the column (section) widths explicitly. You just need to set that as the header view for your table QTableView::setHorizontalHeader().

There may be other ways.