कोड:
widget->setStyleSheet("background-color: red");
ठीक काम करता है, लेकिन आप हर कंटेनर विजेट आप अपनी तालिका में जोड़ने के लिए शैली निर्धारित करने की आवश्यकता:
तो आदेश परिवर्तन आप निम्नलिखित कोड की जरूरत को देखने के लिए:
QWidget *widget = new QWidget();
widget->setStyleSheet("background-color: red");
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);
QWidget *widget2 = new QWidget();
widget2->setStyleSheet("background-color: red");
QCheckBox *checkBox2 = new QCheckBox();
QHBoxLayout *layout2 = new QHBoxLayout(widget2);
layout2->addWidget(checkBox2);
layout2->setAlignment(Qt::AlignCenter);
layout2->setContentsMargins(0, 0, 0, 0);
widget2->setLayout(layout);
ui->tableWidget->setCellWidget(0, 0, widget);
ui->tableWidget->setCellWidget(0, 1, widget2);
और परिणाम होगा:
स्रोत
2014-10-09 19:27:45
लौटाता है यह काम करता है। लेकिन केवल पिछली पृष्ठभूमि बदल गई सेल ने पृष्ठभूमि सेट की है। पिछली कोशिकाओं की पृष्ठभूमि पुनर्प्राप्त। – Ufx
@Ufx मेरे संपादन देखें –