Qt5 - setting background color to QPushButton and QCheckBox

后端 未结 6 677
小蘑菇
小蘑菇 2020-12-06 05:01

I\'m trying to change the background color of a QAbstractButton (either a QPushButton or QCheckBox) in Qt5 and having zero luck.

This does nothing:

p         


        
6条回答
  •  -上瘾入骨i
    2020-12-06 05:32

    Try this:

    QColor col = QColor(Qt::blue);
    if(col.isValid()) {
       QString qss = QString("background-color: %1").arg(col.name());
       button->setStyleSheet(qss);
    }
    

    as mentioned at the QT Forum by @goetz.

    I used some different definition of Qcolor col as QColor col = QColor::fromRgb(144,238,144); and this works for me.

提交回复
热议问题