gpt4 book ai didi

qt - 为什么文本的宽度/高度和 anchor 在 QML 中发生冲突?

转载 作者:行者123 更新时间:2023-12-04 04:33:20 31 4
gpt4 key购买 nike

我想指定文本的宽度和高度,以便 fontSizeMode:Text.Fit 可以工作。但在那之后,文本的 anchor 将不起作用。这怎么会发生?

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!"
}
}
}

最佳答案

嗯,他们工作得很好。但是由于您设置了宽度和高度,centrerIn anchor 不要改变任何东西,因为文本已经在父级中间。您应该设置对齐方式,以获得适当的效果:

Text {
anchors.fill: parent
font.pixelSize: 100
fontSizeMode: Text.Fit
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: "Hello, world!"
}

关于qt - 为什么文本的宽度/高度和 anchor 在 QML 中发生冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20186730/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com