QML CheckBox设置文字大小

时间:2018-10-30 15:45:57

标签: qt checkbox text qml

是否可以设置复选框中使用的文本大小?

我有以下代码:

CheckBox {
    text: qsTr("Use Delays")
    checked: false
    anchors.horizontalCenter: parent.horizontalCenter
    onCheckedChanged:
    {
        middle.useDelays = checked
    }

}

非常感谢!

2 个答案:

答案 0 :(得分:1)

您可以使用CheckBoxStyle.label来定义Text显示的CheckBox项目

import QtQuick.Controls.Styles 1.4

CheckBox {
    style: CheckBoxStyle {
        label: Text {
            text: "Label"
            font.pointSize: 16
        }
    }
}

答案 1 :(得分:1)

对于QtQuick Controls 2,您可以执行以下操作:

https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-checkbox

import QtQuick 2.12
import QtQuick.Controls 2.12

CheckBox {
    id: control
    text: qsTr("CheckBox")
    checked: true

    indicator: Rectangle {
        implicitWidth: 26
        implicitHeight: 26
        x: control.leftPadding
        y: parent.height / 2 - height / 2
        radius: 3
        border.color: control.down ? "#17a81a" : "#21be2b"

        Rectangle {
            width: 14
            height: 14
            x: 6
            y: 6
            radius: 2
            color: control.down ? "#17a81a" : "#21be2b"
            visible: control.checked
        }
    }

    contentItem: Text {
        text: control.text
        font: control.font
        opacity: enabled ? 1.0 : 0.3
        color: control.down ? "#17a81a" : "#21be2b"
        verticalAlignment: Text.AlignVCenter
        leftPadding: control.indicator.width + control.spacing
    }
}