包装文本的边界框 [英] Bounding box of wrapped text

查看:39
本文介绍了包装文本的边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用自动换行的 QML Text 对象周围绘制一个矩形.TextMetrics 似乎是这样理想,但它似乎不支持换行文本.

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.

如何衡量文本在 Text 对象中的布局?我是否必须匹配包装逻辑并使用 TextMetricsFontMetrics?

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?

推荐答案

您可以使用 contentWidthcontentHeight:

You can use contentWidth and contentHeight:

Text {
    text: "..."
    wrapMode: Text.Wrap

    Rectangle {
        border.color: "red"
        color: "transparent"
        width: parent.contentWidth
        height: parent.contentHeight
    }
}

这篇关于包装文本的边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆