Reputation: 303441
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
?
Upvotes: 3
Views: 1184
Reputation: 5836
You can use contentWidth
and contentHeight
:
Text {
text: "..."
wrapMode: Text.Wrap
Rectangle {
border.color: "red"
color: "transparent"
width: parent.contentWidth
height: parent.contentHeight
}
}
Upvotes: 3