如何设置复选框的文字大小

问题描述 投票:0回答:2

有没有办法设置复选框文本的大小?

我有以下代码:

CheckBox {
    text: qsTr("Use Delays")
    checked: false
    anchors.horizontalCenter: parent.horizontalCenter
    onCheckedChanged:
    {
        middle.useDelays = checked
    }
}
qt checkbox qml
2个回答
2
投票

您可以使用

Text
 定义 
CheckBox
显示的
CheckBoxStyle.label

项目
import QtQuick.Controls.Styles 1.4

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

2
投票

对于

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
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.