Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to change the text color of a checkbox?
Forum Update on Monday, May 27th 2025

How to change the text color of a checkbox?

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 6 Posters 7.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rubikon
    wrote on 30 Aug 2013, 11:33 last edited by
    #1

    How can I change the text color of a checkbox?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Buckets
      wrote on 30 Aug 2013, 16:52 last edited by
      #2

      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.

      ba ba ba
      ba na na na

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rubikon
        wrote on 4 Sept 2013, 10:13 last edited by
        #3

        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...

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 4 Sept 2013, 11:49 last edited by
          #4

          Hi,

          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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rubikon
            wrote on 5 Sept 2013, 16:51 last edited by
            #5

            Does this also applies for QML?

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

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DBoosalis
              wrote on 7 Sept 2013, 16:16 last edited by
              #6

              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 ?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                ArpenteurDeToile
                wrote on 20 Jan 2016, 10:03 last edited by
                #7

                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!

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MedDou
                  wrote on 14 Aug 2020, 09:20 last edited by
                  #8

                  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.

                  Cheers.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved