It is easy to know the adaptive column width on the internet, 100% is not left blank display, here still mention:
/*设置表格是否充满,即行末不留空*/ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
Set the effect after 100% not empty:
Before QT5, the automatic width can be achieved by the following program:
/*QT5版本之前设置自动等宽*/ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
But to the QT5 this will not work, need to be set by the following code:
/*设置tablewidget等宽*/QHeaderView* headerView = ui->tableWidget->horizontalHeader();headerView->setSectionResizeMode(QHeaderView::Stretch);/*或者下面的代码*/ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
Set the effect after the auto-equal width:
http://blog.csdn.net/freeape/article/details/48713393
Set tablewidget Adaptive column widths and set auto-width