FontLoader Element Reference

The FontLoader element allows fonts to be loaded by name or URL.

This element was introduced in Qt 4.7.

Detailed Description

The FontLoader element allows fonts to be loaded by name or URL.

The FontLoader element is used to load fonts by name or URL.

The status indicates when the font has been loaded, which is useful for fonts loaded from remote sources.

For example:

  1. import QtQuick 1.0
  2.  
  3. Column  {
  4.     FontLoader  { id: fixedFont; name: "Courier" }
  5.     FontLoader  { id: webFont; source: "http://www.mysite.com/myfont.ttf" }
  6.  
  7.     Text  { text: "Fixed-size font"; font.family: fixedFont.name }
  8.     Text  { text: "Fancy font"; font.family: webFont.name }
  9. }

Properties

Property Documentation

This property holds the name of the font family. It is set automatically when a font is loaded using the url property.

Use this to set the font.family property of a Text item.

Example:

  1.                 Item  {
  2.     width: 200; height: 50
  3.  
  4.     FontLoader  {
  5.         id: webFont
  6.         source: "http://www.mysite.com/myfont.ttf"
  7.     }
  8.     Text  {
  9.         text: "Fancy font"
  10.         font.family: webFont.name
  11.     }
  12. }

The url of the font to load.

This property holds the status of font loading. It can be one of:

  • FontLoader.Null - no font has been set
  • FontLoader.Ready - the font has been loaded
  • FontLoader.Loading - the font is currently being loaded
  • FontLoader.Error - an error occurred while loading the font

Use this status to provide an update or respond to the status change in some way. For example, you could:

  • Trigger a state change:
    1.                         State  { name: 'loaded'; when: loader.status == FontLoader.Ready }
  • Implement an onStatusChanged signal handler:
    1.                         FontLoader  {
    2.     id: loader
    3.     onStatusChanged: if (loader.status == FontLoader.Ready) console.log('Loaded')
    4. }
  • Bind to the status value:
    1.                         Text  { text: loader.status == FontLoader.Ready ? 'Loaded' : 'Not loaded' }
Notes provided by the Qt Community

No notes