1
在研究QML和QtQuick的过程中,出现了以下问题。如何通过减少它所在的元素来使文本自动缩小字体大小。 现在我有这个方法在qml中自动调整文本
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
}
}
}
我看着这些方法,但由于某些原因,有没有效果 –
@v_sith_v:您可以编辑您的问题,包括与'fontSizeMode'属性你试试? – derM
我想出了这个问题。你的建议是对的。谢谢 –