Qt 为什么是文本';s宽度/高度和锚固件在QML中冲突?
我想指定文本的宽度和高度,以便fontSizeMode:Text.Fit可以工作。但在那之后,文本的锚就不起作用了。这怎么会发生Qt 为什么是文本';s宽度/高度和锚固件在QML中冲突?,qt,qml,qtquick2,Qt,Qml,Qtquick2,我想指定文本的宽度和高度,以便fontSizeMode:Text.Fit可以工作。但在那之后,文本的锚就不起作用了。这怎么会发生 Rectangle { width: 360; height: 360 Rectangle { width: parent.width / 3; height: parent.height / 6 anchors.centerIn: parent border{ color: "red"; width:
Rectangle {
width: 360; height: 360
Rectangle {
width: parent.width / 3; height: parent.height / 6
anchors.centerIn: parent
border{ color: "red"; width: 5 }
Text {
anchors {
centerIn: parent
// verticalCenter: parent.verticalCenter
// horizontalCenter: parent.horizontalCenter
}
width: parent.width
height: parent.height
font.pixelSize: 50
fontSizeMode: Text.Fit
text: "Hello, world!"
}
}
}
嗯,他们工作得很好。但由于您设置了宽度和高度,
centerrin
anchor不会更改任何内容,因为文本已经位于父对象的中间。您应该设置对齐,以获得适当的效果:
Text {
anchors.fill: parent
font.pixelSize: 100
fontSizeMode: Text.Fit
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: "Hello, world!"
}