FontLoader QML Type
允许通过 URL 加载字体。更多
Import Statement: | import QtQuick |
属性
详细说明
FontLoader 类型用于通过 URL 加载字体。
status 表示字体何时被加载,这对于从远程源加载字体非常有用。
例如
import QtQuick 2.0 Column { FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" } Text { text: "Fancy font"; font: webFont.font } }
另请参阅 Qt Quick 示例 - 文本字体。
属性文档
font : font |
该属性包含已加载字体的默认查询。
如果需要使用除族名以外的其他属性来消除歧义,可以使用该属性来选择字体。您可以使用单个属性指定字体:
Item { width: 200; height: 50 FontLoader { id: webFont source: "http://www.mysite.com/myfont.ttf" } Text { text: "Fancy font" font.family: webFont.font.family font.weight: webFont.font.weight font.styleName: webFont.font.styleName font.pixelSize: 24 } }
或者直接设置完整的字体查询:
Item { width: 200; height: 50 FontLoader { id: webFont source: "http://www.mysite.com/myfont.ttf" } Text { text: "Fancy font" font: webFont.font } }
在这种情况下,将使用默认字体查询,不做任何修改(例如,字体大小将使用系统默认值)。
该属性在 Qt 6.0 中引入。
name : string |
该属性包含字体族的名称。它在使用source 属性加载字体时自动设置。
该属性等同于FontLoader 的font 属性的族属性。
使用此属性可设置Text
项的font.family
属性。
示例:
Item { width: 200; height: 50 FontLoader { id: webFont source: "http://www.mysite.com/myfont.ttf" } Text { text: "Fancy font" font.family: webFont.name } }
source : url |
要加载字体的 URL。
status : enumeration |
此属性表示字体加载的状态。它可以是
常量 | 说明 |
---|---|
FontLoader.Null | 未设置字体 |
FontLoader.Ready | 字体已加载 |
FontLoader.Loading | 正在加载字体 |
FontLoader.Error | 加载字体时发生错误 |
使用此状态可提供更新或以某种方式响应状态变化。例如,您可以
- 触发状态更改:
State { name: 'loaded'; when: loader.status == FontLoader.Ready }
- 执行
onStatusChanged
信号处理器:FontLoader { id: loader onStatusChanged: if (loader.status == FontLoader.Ready) console.log('Loaded') }
- 绑定状态值:
Text { text: loader.status == FontLoader.Ready ? 'Loaded' : 'Not loaded' }
© 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.