QTableWidgetItem: Headers and centering items
Hi all,
I have a QTableWidget (QT 4.2) which contains checkboxs. I have two questions:
1) Is there a way of centering the checkboxes in each cell.By default they are all aligned to the left.
2) How can I add a combobox, checkbox to the horizontal headers of the table?
Thanks in advance for any help.
Re: QTableWidgetItem: Headers and centering items
QTableWidgetItem questions
Hi all,
I have a QTableWidget (QT 4.2) which contains checkboxs. I have two questions:
1) Is there a way of centering the checkboxes in each cell.By default they are all aligned to the left.
2) How can I add a combobox, checkbox to the horizontal headers of the table?
Thanks in advance for any help.
1 Attachment(s)
Re: QTableWidgetItem: Headers and centering items
1) I assume the checkboxes don't have any text.
Do the following:
Code:
/*******/
l->setSpacing(0);
l->setMargin(0);
l->addWidget(check);
w->setLayout(l);
/*******/
ui.tableWidget->setIndexWidget(ui.tableWidget->model()->index(0,0), w);
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