How to change the text color of a checkbox?
-
wrote on 30 Aug 2013, 11:33 last edited by
How can I change the text color of a checkbox?
-
wrote on 30 Aug 2013, 16:52 last edited by
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.
-
wrote on 4 Sept 2013, 10:13 last edited by
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...
-
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
-
wrote on 5 Sept 2013, 16:51 last edited by
Does this also applies for QML?
I've already done this for QWidgets. But how can i do this for QML Components?
-
wrote on 7 Sept 2013, 16:16 last edited by
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 ?
-
wrote on 20 Jan 2016, 10:03 last edited by
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! -
wrote on 14 Aug 2020, 09:20 last edited by
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.windowTextcontentItem: 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.