If you are using Qt 5, QHeaderView::setResizeMode() is no longer available. Instead, you can use QHeaderView::setSectionResizeMode():
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
Or just call it for every column:
for (int c = 0; c < ui->tableView->horizontalHeader()->count(); ++c)
{
ui->tableView->horizontalHeader()->setSectionResizeMode(
c, QHeaderView::Stretch);
}
Use view->horizontalHeader()->setStretchLastSection(true) to make the last column expand to free space.
Additionally, use view->horizontalHeader()->setResizeMode(QHeaderView::Stretch) to give columns the same width.
Here works using only with:
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
I'm using Qt 5.2!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With