本页内容

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
}

另请参阅 QFontMetricsF 和TextMetrics 。

属性文档

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 、height 以及xHeight 。

descent : real [read-only]

该属性用于指定字体的下沉量。

另请参阅 QFontMetricsF::descent()、ascent 以及height 。

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()。

方法文档

real advanceWidth(string text)

该方法返回text 中字符的进距(以像素为单位)。这是从字符串当前位置到应绘制下一个字符串位置之间的距离。

该方法作为 `TextMetrics` 类中 `advanceWidth ` 属性的命令式替代方案而提供。

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

rect boundingRect(string text)

该方法返回由text 指定的字符串中字符的包围矩形。

此方法作为 `TextMetrics` 的 `boundingRect ` 属性的命令式替代方案提供。

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

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

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

mode 参数指定文本省略模式;即在显示无法完全显示的文本时,省略号应出现在何处。

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

此方法作为 `TextMetrics` 的 `elidedText ` 属性的命令式替代方案提供。

另请参阅 Qt::TextElideMode 和QFontMetricsF::elidedText()。

rect tightBoundingRect(string text)

该方法返回一个紧包住由text 指定的字符串中所有字符的边界矩形。

该方法作为 `TextMetrics` 对象的 `tightBoundingRect ` 属性的命令式替代方案提供。

另请参阅 QFontMetricsF::tightBoundingRect() 和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.