【发布时间】:2016-04-01 19:14:19
【问题描述】:
我想获得Text 元素的实际宽度和高度。如果我使用 paintedWidth 和 paintedHeight 属性,我不明白。例如:
Rectangle {
color: "green"
width: a_text.paintedWidth
height: a_text.paintedHeight
Text {
id: a_text
text: "r"
color: "white"
anchors.centerIn: parent
}
}
如果我运行该代码,我会在"r" 顶部和"r" 下方看到"r" 左侧的一些绿色空间。所以我没有得到Text 的真实宽度和高度。我的意思是,白色像素的宽度和高度。
有什么办法吗?
附:我还需要文本真正的左上角的相对位置,我的意思是,左上角白色像素相对于Text 的“官方”左上角像素的 x 和 y。
【问题讨论】:
-
很高兴您解决了您的问题