0

I have a checkbox in Qt that I want to change its style from the one in the picture below:

enter image description here

to the one in the picture below:

enter image description here

What I've tried so far is:

QCheckBox::indicator::checked
{
background-color: rgb(24, 144, 255);
indicator: white;
}

result:

enter image description here

the check inside checkbox disappears

temp
  • 121
  • 7

1 Answers1

0

You are on the right track. You can either use an image or a font like Font Awesome to be loaded. For example, the QML example below uses the checkmark unicode as the text property. You can use a FontLoader to load the font or see if you have a system font that has a checkmark.

FontLoader {
   id: fontAwesome
   source: "qrc:<path>/fontawesome.otf"
}

CheckDelegate {
    contentItem: Label {
        ...
    }

    background: Rectangle {
        ...
        color: "white"
    }

    indicator: Rectangle {
        ...
        Text {
            text: checked ? "\uf00c" : ""
            font.family: fontAwesome.name // Setup from FontLoader
        }
    }
}
slayer
  • 643
  • 7
  • 14
  • I was trying to avoid the usage of an image but if it's like so I'm afraid that I have no other choice – temp Jun 02 '21 at 07:24
  • 1
    The font unicode style is probably the most convenient as it supports SVG and keeps your package size small. Or else the image will have to be embedded within the executable as a resource. Plus you might use the font in other places as well for nice button design. – slayer Jun 02 '21 at 14:46