IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

FontLoader QML Type

Allows fonts to be loaded by name or URL.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

FontLoader QML Type

  • Import Statement: import QtQuick 2.13

  • Group: FontLoader is part of qtquick-text-utility

Detailed Description

The FontLoader type 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:

 
Sélectionnez
import QtQuick 2.0

Column {
    FontLoader { id: fixedFont; name: "Courier" }
    FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" }

    Text { text: "Fixed-size font"; font.family: fixedFont.name }
    Text { text: "Fancy font"; font.family: webFont.name }
}

See Also

Property Documentation

 

name : string

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

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

Example:

 
Sélectionnez
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

The URL of the font to load.

status : enumeration

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:

     
    Sélectionnez
    State { name: 'loaded'; when: loader.status == FontLoader.Ready }
  • Implement an onStatusChanged signal handler:

     
    Sélectionnez
    FontLoader {
        id: loader
        onStatusChanged: if (loader.status == FontLoader.Ready) console.log('Loaded')
    }
  • Bind to the status value:

     
    Sélectionnez
    Text { text: loader.status == FontLoader.Ready ? 'Loaded' : 'Not loaded' }

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+