FontMetrics QML Type

为指定字体提供度量指标。更多

Import Statement: import QtQuick

属性

方法

详细说明

FontMetrics 可计算给定字体的字符和字符串大小。

它提供了 C++QFontMetricsF API 的子集,并增加了通过font 属性更改计算所用字体的功能。

FontMetrics {
    id: fontMetrics
    font.family: "Arial"
}

Rectangle {
    width: fontMetrics.height * 4
    height: fontMetrics.height * 2
}

另请参见 QFontMetricsFTextMetrics

属性文档

ascent : real [read-only]

该属性用于保存字体的升序。

另请参阅 QFontMetricsF::ascent(),descent, 和height


averageCharacterWidth : real [read-only]

该属性表示字体中字形的平均宽度。

另请参阅 QFontMetricsF::averageCharWidth() 。


capitalHeight : real [read-only, since 6.9]

返回字体指定的大写高度。

字体的大写高度定义为大写字母高于基线的高度。它具体指的是扁平大写字母(如 H 或 I)的高度,而不是圆形字母(如 O)或尖形字母(如 A)的高度,这两种字母都可能显示超调。

该属性在 Qt 6.9 中引入。

另请参见 QFontMetricsF::capHeight,ascent,descent,heightxHeight


descent : real [read-only]

该属性保留了字体的后退。

另请参阅 QFontMetricsF::descent() 、ascentheight


font : font

该属性用于保存度量计算所用的字体。


height : real [read-only]

该属性保存字体的高度。

另请参阅 QFontMetricsF::height() 。


leading : real [read-only]

该属性用于设置字体的前导。

另请参见 QFontMetricsF::leading()。


lineSpacing : real [read-only]

该属性用于保存从一条基线到下一条基线的距离。

另请参见 QFontMetricsF::lineSpacing()。


lineWidth : real [read-only]

该属性表示下划线和删除线的宽度,根据字体的点大小进行调整。

另请参见 QFontMetricsF::lineWidth()。


maximumCharacterWidth : real [read-only]

该属性用于保存字体中最宽字符的宽度。

另请参阅 QFontMetricsF::maxWidth()。


minimumLeftBearing : real [read-only]

该属性用于保存字体的最小左方位。

另请参阅 QFontMetricsF::minLeftBearing()。


minimumRightBearing : real [read-only]

该属性用于保存字体的最小右方位。

另请参阅 QFontMetricsF::minRightBearing()。


overlinePosition : real [read-only]

该属性用于保存从基准线到应绘制的过度线之间的距离。

另请参阅 QFontMetricsF::overlinePos(),underlinePosition, 和strikeOutPosition


strikeOutPosition : real [read-only]

该属性用于保存从基线到应绘制删除线的距离。

另请参阅 QFontMetricsF::strikeOutPos(),overlinePosition, 和underlinePosition


underlinePosition : real [read-only]

该属性表示从基线到下划线的距离。

另请参阅 QFontMetricsF::underlinePos(),overlinePosition, 和strikeOutPosition


xHeight : real [read-only]

该属性表示字体的 "x "高度。

另请参阅 QFontMetricsF::xHeight() 。


方法文档

qreal advanceWidth(string text)

本方法以像素为单位返回text 中字符的前进方向。这是从字符串位置到下一个字符串位置的距离。

该方法是TextMetricsadvanceWidth 属性的命令式替代方法。

另请参阅 QFontMetricsF::horizontalAdvance() 和QFontMetricsF::height()。


rect boundingRect(string text)

该方法返回text 指定的字符串中字符的边界矩形。

该方法是TextMetricsboundingRect 属性的命令式替代方法。

另请参阅 QFontMetricsF::boundingRect() 和tightBoundingRect()。


string elidedText(string text, enumeration mode, real width, int flags)

如果text 的宽度大于width ,该方法将返回字符串的省略版本(即包含"... "的字符串)。否则,将返回原始字符串。

mode 参数指定文本省略模式,即在显示不合适的文本时,省略号应显示在哪里。

flags 参数是可选的,目前只支持Qt::TextShowMnemonic

该方法是TextMetricselidedText 属性的命令式替代方法。

另请参阅 Qt::TextElideModeQFontMetricsF::elidedText()。


rect tightBoundingRect(string text)

该方法返回text 所指定字符串中字符周围的紧密包围矩形。

该方法是TextMetricstightBoundingRect 属性的命令式替代方法。

另请参阅 QFontMetricsF::tightBoundingRect() 和boundingRect()。


© 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.