1) I assume the checkboxes don't have any text.
Do the following:
/*******/
l->setSpacing(0);
l->setMargin(0);
l->addWidget(check);
w->setLayout(l);
/*******/
ui.tableWidget->setIndexWidget(ui.tableWidget->model()->index(0,0), w);
/*******/
QWidget *w = new QWidget(ui.tableWidget);
QHBoxLayout *l = new QHBoxLayout(w);
l->setSpacing(0);
l->setMargin(0);
l->addItem(new QSpacerItem(1,1, QSizePolicy::Expanding, QSizePolicy::Fixed));
QCheckBox* check = new QCheckBox(w);
check->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
l->addWidget(check);
l->addItem(new QSpacerItem(1,1, QSizePolicy::Expanding, QSizePolicy::Fixed));
w->setLayout(l);
/*******/
ui.tableWidget->setIndexWidget(ui.tableWidget->model()->index(0,0), w);
To copy to clipboard, switch view to plain text mode
So instead of just a checkbox you should add a custom widget, consisting of a horizontal layout a left spacer, the checkbox and a right spacer. The spacers are there to keep the checkbox centered.
2) No answer. I'm afraid that is pretty hard to do.
AFAIK there is a custom widget(commercial) that does that. I've seen it mentioned in a post(here, on QtCentre) some time a go.
BTW, regarding 1, the checkbox is not 100% centered because even with no text it still keeps a few pixels at its right side. You can notice that if you call setAutofillBackground(true) for the checkbox.
Regards
Bookmarks