1 Attachment(s)
How to set the QTableWidget's columns width to fit the widget
I'm using a QTableWidget, but I'm looking for a way to dynamically resize the columns to fit the widget base width.
I tried this, but it's resizing the column contents only to fit it's column. But I need the columns resize itself to the widget's width.
Code:
for(int nCol, nRow = 0; nRow < 3; nRow++)
{
for(nCol = 0; nCol < 4; nCol++)
{
vulnTable->resizeRowsToContents();
vulnTable->resizeColumnsToContents();
}
}
And the result is as shown in the pic. How do I avoid the gap left-out?
Attachment 9097
Thank you.
Re: How to set the QTableWidget's columns width to fit the widget
Use this
Code:
QTableWidget::horizontalHeader().
setStretchLastSection(true);
Re: How to set the QTableWidget's columns width to fit the widget
use this
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
Re: How to set the QTableWidget's columns width to fit the widget
For QTableWidget::horizontalHeader().setStretchLastSec tion(true);
Code:
error: C2228: left of '.setStretchLastSection' must have class/struct/union
type is 'QHeaderView *'
did you intend to use '->' instead?
And if I try this - tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
Code:
error: C2027: use of undefined type 'QHeaderView'
error: C2065: 'Stretch' : undeclared identifier
NB: It's not even giving suggestions after horizontalHeader(). I'm using Qt 5.0.2
Re: How to set the QTableWidget's columns width to fit the widget
Code:
QTableWidget::horizontalHeader().
setStretchLastSection(true);
Worked. Thanks
Re: How to set the QTableWidget's columns width to fit the widget
Quote:
Originally Posted by
pradeepreddyg95
use this
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
Hi... you suggestion was useful
1 Attachment(s)
Re: How to set the QTableWidget's columns width to fit the widget
I have another problem after doing this, header then cut like the this image Attachment 11373
the second column in the first table is [Manufacturer]
the second column header is [Apical Diameter] and the third column is [Occlusal Diameter]
how can i make the table fit width of both header and content and also the columns resize itself to the widget's width.
thanks