Qt5 - setting background color to QPushButton and QCheckBox

后端 未结 6 691
小蘑菇
小蘑菇 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条回答
  •  孤城傲影
    2020-12-06 05:13

    I had the same issue, but finally got this to work. I'm using Qt 5 with the Fusion color theme:

    QPalette pal = button->palette();
    pal.setColor(QPalette::Button, QColor(Qt::blue));
    button->setAutoFillBackground(true);
    button->setPalette(pal);
    button->update();
    

    Try these commands in the exact order as above, and if that still doesn't work, set your theme to Fusion and try again.

    Good luck!

提交回复
热议问题