1,直接添加控件
for(int i = 0; i < tableCount; ++i) {
const QString table = tableNames.at(i);
{
QWidget *widget = new QWidget(ui->tableWidget_table);
QHBoxLayout *hLayout = new QHBoxLayout();
QCheckBox *checkBox = new QCheckBox();
hLayout->addWidget(checkBox);
hLayout->setMargin(0); // 必须添加, 否则CheckBox不能正常显示
hLayout->setAlignment(checkBox, Qt::AlignCenter);
widget->setLayout(hLayout);
ui->tableWidget_table->setCellWidget(i, TABLE_CHECKED_COLUMN, widget);
}
2,使用代理 实例里面有的