TextMetrics QML Type
为给定字体和文本提供度量指标。更多
| Import Statement: | import QtQuick |
属性
- advanceWidth : real
- boundingRect : rect
- elide : enumeration
- elideWidth : real
- elidedText : string
- font : font
- height : real
- renderType : enumeration
(since 6.3) - text : string
- tightBoundingRect : rect
- width : real
详细说明
TextMetrics 可计算特定字体下给定文本字符串的各种属性。
它为QFontMetricsF 中需要参数的函数提供了声明式 API。
TextMetrics {
id: textMetrics
font.family: "Arial"
elide: Text.ElideMiddle
elideWidth: 100
text: "Hello World"
}
MyItem {
text: textMetrics.elidedText
}另请参见 QFontMetricsF 和FontMetrics 。
属性文档
advanceWidth : real [read-only]
该属性用于保存text 中字符的提前量(以像素为单位)。这是从字符串位置到下一个字符串绘制位置的距离。
另请参阅 QFontMetricsF::horizontalAdvance() 。
boundingRect : rect [read-only]
该属性保存text 指定的字符串中字符的边界矩形。
另请参阅 QFontMetricsF::boundingRect() 和tightBoundingRect 。
elide : enumeration
该属性用于保存文本的省略模式。这决定了字符串被省略的位置。可能的值有
| 常量 | 说明 |
|---|---|
Qt::ElideNone | 不消除;这是默认值。 |
Qt::ElideLeft | 例如"......世界" |
Qt::ElideMiddle | 例如:".....:"他......ld" |
Qt::ElideRight | 例如:"Hello...例如:"Hello......" |
另请参见 elideWidth 和QFontMetrics::elidedText 。
elideWidth : real
该属性用于保存文本在发生移除之前的最大宽度(以像素为单位)。
另请参阅 elide 和QFontMetrics::elidedText 。
elidedText : string [read-only]
如果text 的宽度大于elideWidth ,此属性将保存字符串的省略版本(即包含"... "的字符串)。如果文本的宽度不大于elideWidth ,或elide 设置为Qt::ElideNone ,此属性将等于原始字符串。
另请参阅 QFontMetricsF::elidedText() 。
font : font
该属性包含用于度量计算的字体。
height : real [read-only]
该属性用于保存text 指定的字符串中字符的边界矩形高度。它等同于
textMetrics.boundingRect.height
另请参见 boundingRect 。
renderType : enumeration [since 6.3]
覆盖此组件的默认呈现类型。
支持的呈现类型有
| 常量 | 描述 |
|---|---|
TextEdit.QtRendering | 使用每个字形的可缩放距离字段渲染文本。 |
TextEdit.NativeRendering | 使用特定平台技术呈现文本。 |
这应与您绘制文本的预期renderType 匹配。
此属性在 Qt 6.3 中引入。
另请参阅 Text.renderType 。
text : string
该属性包含用于度量计算的文本。
tightBoundingRect : rect [read-only]
该属性会在text 指定的字符串中的字符周围保留一个紧密的矩形边界。
另请参阅 QFontMetricsF::tightBoundingRect() 和boundingRect 。
width : real [read-only]
该属性用于保存text 指定的字符串中字符的边界矩形宽度。它等同于
textMetrics.boundingRect.width
另请参见 boundingRect 。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.