Qt QTableWidget Column resizing
- Change the
ResizeMode
of theQHeaderView
. For example, use:
horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
to make the first column resize so the QTableWidget
is always full.
- Override the
resizeEvent
and set the widths of each column yourself when theQTableWidget
has been resized.
To stretch last column:
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
To stretch column #n:
ui->tableWidget->horizontalHeader()->setSectionResizeMode(n, QHeaderView::Stretch);
The best solution for this, in Qt5 you have to use setSectionResizeMode
instead of setResizeMode
tabv = QTableView()
tabv.horizontalHeader().setSectionResizeMode(QHeaderView::Stretch)
Also you can specify the Stretch
mode when resizing
tabv.horizontalHeader().resizeSections(QHeaderView::Stretch)