Change text color for QML controls

↘锁芯ラ 提交于 2019-12-05 05:46:25
koopajah

You need to use the style property to redefine the Component to use for the label based on the CheckBoxStyle

import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.0

Rectangle {
    color: "black"
    CheckBox {
        style: CheckBoxStyle {
            label: Text {
                color: "white"
                text: "check Me"
            }
        }
    }
}

When using CheckBoxStyle you might have to redefine the whole component and not just the label property.

I had the same problem with GroupBox so I wanted to post an answer for future reference. The problem can easily be fixed using HTML formatting. For instance to change the color:

GroupBox{ 
    title: "<font color=\"white\">my title</font>"
}

Size and other formatting parameters can be changed the same way.

Have you tried setting it as an entire sub-element of the checkbox?

CheckBox {

    Text {
        text: "Check Me"
        color: "red"
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!