Bounding box of wrapped text

二次信任 提交于 2019-12-23 18:55:45

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!