QToolButton, QPushButton { background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(254, 254, 254, 255), stop:1 rgba(208, 208, 208, 255)); border: 2px solid rgba(178, 178, 178, 255); border-radius: 5px; padding: 2px;}QToolButton:checked, QPushButton:checked { background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(57, 181, 74, 255), stop:1 rgba(7, 150, 70, 255)); border-color: rgba(0, 146, 69, 255); border-style: inset;}QToolButton:pressed, QPushButton:pressed { background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(57, 181, 74, 255), stop:1 rgba(7, 150, 70, 255)); border-color: rgba(0, 146, 69, 255); border-style: inset;}
CSSQCheckBox::checked { color: red; } QLabel[checked="true"] { color: red; }
C++ (Qt)...private slots: void changeChecked(bool checked);private: void setLabelChecked(QLabel* label, bool checked);...
C++ (Qt)Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget){ ui->setupUi(this); connect(ui->checkBox, &QAbstractButton::toggled, this, &Widget::changeChecked); setLabelChecked(ui->checkBox_label, ui->checkBox->isChecked()); connect(ui->checkBox_2, &QAbstractButton::toggled, this, &Widget::changeChecked); setLabelChecked(ui->checkBox_2_label, ui->checkBox_2->isChecked());} void Widget::changeChecked(bool checked){ if (!sender()) { return; } QLabel* label = sender()->parent()-> findChild<QLabel*>(sender()->objectName() + "_label"); if (label) { setLabelChecked(label, checked); }} void Widget::setLabelChecked(QLabel* label, bool checked){ label->setProperty("checked", checked); label->style()->unpolish(label); label->style()->polish(label); label->update();}