FontLoader QML Type
Consente di caricare i font tramite URL. Altro...
| Import Statement: | import QtQuick |
Proprietà
Descrizione dettagliata
Il tipo FontLoader viene utilizzato per caricare i font tramite URL.
L'status a indica quando il font è stato caricato, il che è utile per i font caricati da fonti remote.
Ad esempio:
import QtQuick 2.0
Column {
FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" }
Text { text: "Fancy font"; font: webFont.font }
}Vedi anche Esempi diQt Quick - Font di testo.
Documentazione delle proprietà
font : font [read-only, since 6.0]
Questa proprietà contiene una query predefinita per il font caricato.
È possibile utilizzarla per selezionare il font qualora, per eliminare eventuali ambiguità, siano necessarie proprietà diverse dal solo nome della famiglia. È possibile specificare il font utilizzando le singole proprietà:
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
}
}oppure impostando direttamente la query completa del font:
Item {
width: 200; height: 50
FontLoader {
id: webFont
source: "http://www.mysite.com/myfont.ttf"
}
Text {
text: "Fancy font"
font: webFont.font
}
}In questo caso, la query predefinita del font verrà utilizzata senza modifiche (quindi, ad esempio, la dimensione del font sarà quella predefinita dal sistema).
Questa proprietà è stata introdotta in Qt 6.0.
name : string [read-only]
Questa proprietà contiene il nome della famiglia di caratteri. Viene impostata automaticamente quando un font viene caricato tramite la proprietà source.
È equivalente alla proprietà family della proprietà font di FontLoader.
Utilizzarla per impostare la proprietà font.family di un elemento Text.
Esempio:
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
L'URL del font da caricare.
status : enumeration [read-only]
Questa proprietà indica lo stato del caricamento dei font. Può assumere uno dei seguenti valori:
| Costante | Descrizione |
|---|---|
FontLoader.Null | non è stato impostato alcun font |
FontLoader.Ready | il font è stato caricato |
FontLoader.Loading | il font è attualmente in fase di caricamento |
FontLoader.Error | si è verificato un errore durante il caricamento del font |
Utilizza questo stato per fornire un aggiornamento o rispondere in qualche modo al cambiamento di stato. Ad esempio, potresti:
- Innescare un cambiamento di stato:
State { name: 'loaded'; when: loader.status == FontLoader.Ready } - Implementare un gestore del segnale "
onStatusChanged":FontLoader { id: loader onStatusChanged: if (loader.status == FontLoader.Ready) console.log('Loaded') } - Associarti al valore dello stato:
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.