我建议在 中定义一个全局属性main.qml
,而不是分别在每个元素中定义文本大小。
为此,main.qml
像这样定义一个属性:
readonly property Item fontCenter: Item {
property real heading1PointSize: 21
property real heading2PointSize: 18
property real bodyPointSize: 12
}
并在任何地方使用它:
Text {
text: "sample body text"
font { pointSize: fontCenter.bodyPointSize }
}
同样,如果您有问题,您可以根据另一个设置属性值:
readonly property Item fontCenter: Item {
property real bodyPointSize: 12
property real heading1PointSize: bodyPointSize * 2.0
property real heading2PointSize: bodyPointSize * 1.8
}
或用于特殊情况,如下所示:
Button {
text: "Special Offer!"
font { pointSize: fontCenter.bodyPointSize * 1.3 }
}