font QML Value Type

QFont font 类型指具有 属性的字体值 ...QFont更多...

详细说明

font 类型的属性默认为应用程序的默认font

最常用的属性有

如果同时指定了pointSizepixelSize ,则将使用pixelSize

以下属性也可用:

  • 枚举 font.weight
  • bool font.overline
  • bool font.strikeout
  • 枚举 font.capitalization
  • real font.letterSpacing
  • real font.wordSpacing
  • bool font.kerning
  • bool font.preferShaping
  • 枚举 font.hintingPreference
  • object font.features
  • string font.styleName
  • object [QML] {QtQuick::Text::}{font.variableAxes}。
  • bool font.contextFontMerging
  • bool font.preferTypoLineMetrics

示例:

    Text {
        font.family: "Helvetica"
        font.pointSize: 13
        font.bold: true
    }

由于fontstructured value 类型,它也可以用 JavaScript 对象构建:

    readonly property font myFont: ({
        family: "Helvetica",
        pointSize: 13,
        bold: true
    })

当与 C++ 整合时,请注意任何从 C++ 传入 QML 的 QFont 值都会自动转换为font 值,反之亦然。

这种值类型由QtQuick import 提供。

字体权重的数值遵循 CSS 规范,权重为 100 表示极轻,900 表示极粗。支持以下值:

常量说明
Font.Thin100
Font.ExtraLight200
Font.Light300
Font.Normal400
Font.Medium500
Font.DemiBold600
Font.Bold700
Font.ExtraBold800
Font.Black900

大写支持以下值:

常量说明
Font.MixedCase不更改大写。
Font.AllUppercase将文本改为全大写。
Font.AllLowercase将文本改成全小写。
Font.SmallCaps将文字改成小写。
Font.Capitalize将文本改为每个单词的第一个字符为大写字符。

设置提示首选项只有在使用 "NativeRendering "呈现类型时才有效。该属性支持以下值:

常量说明
Font.PreferDefaultHinting使用目标平台的默认提示级别。
Font.PreferNoHinting如果可能,渲染文本时不提示字形轮廓。
Font.PreferVerticalHinting如果可能,在渲染文本时不显示水平提示,但在垂直方向将字形与像素网格对齐。
Font.PreferFullHinting如果可能,渲染文本时在水平和垂直方向都有提示。

另请参阅 QML 值类型

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