Qt World Summit: Submit your Presentation

How to change the text color of a checkbox?

  • How can I change the text color of a checkbox?

  • not sure how to change the text color of a checkbox, but you can change the color of a label, and just group the two of them if want the quick and dirty way.

  • Okay this works but is not very elegant.

    Isn't there a more common way? I think this is not a very unusual use-case...

  • Lifetime Qt Champion


    IIRC it's style dependent (to look like the OS) What you could to is use your own image and "Qt's Style Sheet":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qcheckbox to modify the QCheckBox appearance.

    Hope it helps

  • Does this also applies for QML?

    I've already done this for QWidgets. But how can i do this for QML Components?

  • Yes I wanted to know this too. The dcoumentation for CheckBox says there is a style property. I try to implement the example in the documentation:
    CheckBox {
    text: "Check Box"
    style: CheckBoxStyle {
    indicator: Rectangle {
    implicitWidth: 16
    implicitHeight: 16
    radius: 3
    border.color: control.activeFocus ? "darkblue" : "gray"

    But in version 5.1 with QtCreator that it come sith it doesn't like or know what "CheckBoxStyle" is.

    Is the documentation wrong or is just somethng I do not understand ?

  • Hey, I just bumped into that discussion, I know it was 2 years ago, but if anyone has a similar question, the asnwer is simple;
    you need to import QtQuick.Controls.Style 1.4 at least ~
    Enjoy people!

  • Hi,
    I know this is 7 years old but I wanted to share this little shortcut anyway.
    So, by looking at the QML source code of CheckBox there seems to be a property that is bound to the text color: control.palette.windowText

        contentItem: CheckLabel {
            leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0
            rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0
            text: control.text
            font: control.font
            color: control.palette.windowText

    It seems to work quite well though I have done no extensive research on the effects of changing the value of that property.


Log in to reply