477
社区成员
发帖
与我相关
我的任务
分享
QCheckBox *checkBox[] = { new QCheckBox, new QCheckBox, new QCheckBox };
int column[] { 9, 11, 13 };
for (int i = 0; i < 3; i++) {
QWidget *widget = new QWidget;
QHBoxLayout *hLayout = new QHBoxLayout();
hLayout->addWidget(checkBox[i]);
hLayout->setMargin(0);
// 设置水平居中
hLayout->setAlignment(widget, Qt::AlignCenter);
// 设置部件周围的左、上、右、下边距
hLayout->setContentsMargins(10, 0, 10, 0);
// 添加布局
widget->setLayout(hLayout);
// 添加单元格
ui.tableWidget->setCellWidget(row, column[i], widget);
}