在学习QML和QtQuick的过程中,我遇到了以下问题。如何使文本根据其所在元素的大小自动缩小字体大小。
现在我有这个方法:
Rectangle {
id: main_window
width: 700
height: 500
property int main_w: main_window.width
Rectangle {
width: 400
height: 400
anchors.centerIn: parent
color: 'green'
Text {
text: "SIZE ME!!!"
anchors.centerIn: parent
color: 'white'
font.pointSize: {
if (main_window.main_w < main_window.width)
return main_window.main_w / 35 // we need 20pt
return main_window.width / 35
}
visible: {
if (parent.width < 100)
return false
return true
}
}
}
它能够工作,但不是特别优雅。也许有一些方法可以让文本自动调整大小。如果ColumnLayout
中的换行不起作用,请帮忙解决。
请帮忙。谢谢
这是我的代码,尝试使用fontSizeMode
:
Rectangle {
id: root
width: 700
height: 700
property int mrg: 10
Rectangle {
anchors.centerIn: parent
width: 400
height: 400
color: 'green'
Text {
id: field
text: "Size me!"
minimumPointSize: 10
font.pointSize: 60
fontSizeMode: Text.Fit
color: 'white'
anchors.centerIn: parent
}
}
}
fontSizeMode
属性的内容? - derM