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 |
该属性表示text 中字符的前进距离(以像素为单位)。这是从字符串位置到下一个字符串位置的距离。
另请参阅 QFontMetricsF::horizontalAdvance() 。
boundingRect : rect |
该属性保存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 |
如果text 的宽度大于elideWidth ,该属性将保留字符串的省略版本(即包含"... "的字符串)。如果文本的宽度不大于elideWidth ,或elide 设置为Qt::ElideNone
,该属性将等于原始字符串。
另请参阅 QFontMetricsF::elidedText() 。
font : font |
该属性保存用于度量计算的字体。
height : real |
renderType : enumeration |
覆盖此组件的默认呈现类型。
支持的呈现类型有
常量 | 说明 |
---|---|
TextEdit.QtRendering | 使用每个字形的可缩放距离域渲染文本。 |
TextEdit.NativeRendering | 使用特定平台技术呈现文本。 |
这应与您绘制文本的预期renderType
匹配。
此属性在 Qt 6.3 中引入。
另请参阅 Text.renderType 。
text : string |
该属性包含用于度量计算的文本。
tightBoundingRect : rect |
该属性为text 指定的字符串中的字符保留一个紧密的边界矩形。
另请参见 QFontMetricsF::tightBoundingRect() 和boundingRect 。
width : real |
© 2025 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.