Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

change disabled background color QCheckbox?



  • Hi

    Is it possible to change the standard gray-ish background color of a
    QCheckBox::setEnabled(0)?
    Bildschirmfoto_2019-11-11_08-40-57.png

    I tried to set the background via:

    QCheckbox::setStyleSheet("QCheckBox::indicator {background-color:red;}");
    

    but that fills the whole checkbox with that color including the border and the checkmark itself.

    Bildschirmfoto_2019-11-11_08-54-13.png


  • Moderators

    hi @pauledd

    haven't checked it, but using the disabled keyword should work as a selector:

    QCheckBox::indicator:disabled{...}
    

    or simply

    QCheckBox:disabled {...}
    


  • Thanks, with

    QCheckBox:disabled {background-color:red;}
    

    I get this:
    Bildschirmfoto_2019-11-11_09-19-10.png
    and with

    QCheckBox:disabled {color:green;background-color:red;}
    

    this:
    Bildschirmfoto_2019-11-11_09-22-08.png
    still weird looking but I can live with that...
    Thank you.



  • @pauledd
    You mean the background color "overspill" to right & bottom? I don't know but you might play with border-... or padding-... (I'm thinking margin- does not use background color, but I might be wrong) having a width/transparency/grey....