Change text color for QML controls

六眼飞鱼酱① 提交于 2019-12-10 04:21:06

问题


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

回答1:


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.




回答2:


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.




回答3:


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

CheckBox {

    Text {
        text: "Check Me"
        color: "red"
    }
}


来源:https://stackoverflow.com/questions/18474447/change-text-color-for-qml-controls

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