En esta página

FontLoader QML Type

Permite cargar fuentes mediante una URL. Más...

Import Statement: import QtQuick

Propiedades

Descripción detallada

El tipo FontLoader se utiliza para cargar fuentes mediante una URL.

El método « status » indica cuándo se ha cargado la fuente, lo cual resulta útil para fuentes cargadas desde fuentes remotas.

Por ejemplo:

import QtQuick 2.0

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

    Text { text: "Fancy font"; font: webFont.font }
}

Véase también Ejemplos de` Qt Quick `: fuentes de texto.

Documentación de propiedades

font : font [read-only, since 6.0]

Esta propiedad contiene una consulta predeterminada para la fuente cargada.

Puedes utilizarla para seleccionar la fuente si se necesitan otras propiedades, además del nombre de la familia, para evitar ambigüedades. Puedes especificar la fuente utilizando propiedades individuales:

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
    }
}

O bien, se puede establecer directamente la consulta completa de la fuente:

Item {
    width: 200; height: 50

    FontLoader {
        id: webFont
        source: "http://www.mysite.com/myfont.ttf"
    }
    Text {
        text: "Fancy font"
        font: webFont.font
    }
}

En este caso, se utilizará la consulta de fuente predeterminada sin modificaciones (por lo que, por ejemplo, el tamaño de la fuente será el predeterminado del sistema).

Esta propiedad se introdujo en Qt 6.0.

name : string [read-only]

Esta propiedad contiene el nombre de la familia de fuentes. Se establece automáticamente cuando se carga una fuente mediante la propiedad source.

Esto equivale a la propiedad «family» de la propiedad « font » de ` FontLoader`.

Utilízala para establecer la propiedad ` font.family ` de un elemento ` Text `.

Ejemplo:

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

La URL de la fuente que se va a cargar.

status : enumeration [read-only]

Esta propiedad indica el estado de la carga de la fuente. Puede adoptar uno de los siguientes valores:

ConstanteDescripción
FontLoader.Nullno se ha establecido ninguna fuente
FontLoader.Readyse ha cargado la fuente
FontLoader.Loadingla fuente se está cargando en este momento
FontLoader.ErrorSe ha producido un error al cargar la fuente

Utiliza este estado para proporcionar una actualización o responder al cambio de estado de alguna manera. Por ejemplo, podrías:

  • Provocar un cambio de estado:
    State { name: 'loaded'; when: loader.status == FontLoader.Ready }
  • Implementar un controlador de señal « onStatusChanged »:
    FontLoader {
        id: loader
        onStatusChanged: if (loader.status == FontLoader.Ready) console.log('Loaded')
    }
  • Vincularse al valor del estado:
    Text { text: loader.status == FontLoader.Ready ? 'Loaded' : 'Not loaded' }

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