更改 QML 控件的文本颜色 [英] Change text color for QML controls

查看:139
本文介绍了更改 QML 控件的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些 QML 控件,例如 GroupBoxCheckBox 有与之关联的文本.文本的默认颜色为黑色.但是,我将这些项目放在深色背景上,并且更喜欢使用白色作为文本颜色.这些项目没有颜色属性,所以我不知道该怎么做.

I am using some QML controls like GroupBox and CheckBox which have text associated with them. The default color of the text is black. However, I have these items on a dark background and would prefer using white for the text color. These items don't have a color property so I'm not sure what to do.

CheckBox {
    text: "Check Me"
}

推荐答案

您需要使用style 属性重新定义 Component 以用于基于 CheckBoxStyle

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"
            }
        }
    }
}

使用 CheckBoxStyle 时,您可能需要重新定义整个组件,而不仅仅是标签属性.

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

这篇关于更改 QML 控件的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆