问题
I want to draw a rectangle around a QML Text
object that is using word wrapping. TextMetrics seems like it would be ideal, but it does not appear to support wrapped text.
How can I measure how text is laid out in a Text
object? Must I match the wrapping logic and manually calculate the offsets using TextMetrics
and FontMetrics?
回答1:
You can use contentWidth and contentHeight:
Text {
text: "..."
wrapMode: Text.Wrap
Rectangle {
border.color: "red"
color: "transparent"
width: parent.contentWidth
height: parent.contentHeight
}
}
来源:https://stackoverflow.com/questions/39086999/bounding-box-of-wrapped-text