I use QCheckBox
in QTableWidgetCell
QWidget *widget = new QWidget();
QCheckBox *checkBox = new QCheckBox();
QHBoxLayout *layout = new QHBoxLayout(widget);
layout->addWidget(checkBox);
layout->setAlignment(Qt::AlignCenter);
layout->setContentsMargins(0, 0, 0, 0);
widget->setLayout(layout);
table->setCellWidget(0, 0, widget);
How can I change cell background?
You should try this:
If you want to specify it more generally, write the classtype in the CSS to indicate which class in the hierarchy should handle the flag. This could look something like this then:
The code:
works fine but you need to set the style for every container widget you add to your table:
So in order to see the change you need the following code:
And the result will be:
If you want to change cell background, not a widget, use
setBackground()
method:In this case all your cell will be red (without white lines around checkbox).