在網上很容易知道自適應列寬,100%不留空顯示,這里還是提下:
/*設置表格是否充滿,即行末不留空*/ ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
設置了100%不留空后的效果:
在QT5之前,只要通過下面的程序就可以實現自動等寬:
/*QT5版本之前設置自動等寬*/ ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
但是到了QT5這個是行不通了的,需通過下面的代碼來設置:
/*設置tablewidget等寬*/ QHeaderView* headerView = ui->tableWidget->horizontalHeader(); headerView->setSectionResizeMode(QHeaderView::Stretch); /*或者下面的代碼*/ ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
設置自動等寬之后的效果: 
http://blog.csdn.net/freeape/article/details/48713393
