このページでは

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 [read-only, since 6.0]

このプロパティには、読み込まれたフォントのデフォルトのクエリが格納されています。

フォントの曖昧さを解消するために、ファミリー名以外のプロパティが必要な場合、これを使用してフォントを選択できます。個々のプロパティを使用してフォントを指定することも可能です:

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 [read-only]

このプロパティには、フォントファミリーの名前が格納されます。source プロパティを使用してフォントが読み込まれると、自動的に設定されます。

これは、FontLoader のfont プロパティにあるfamilyプロパティと同等です。

これを使用して、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 [read-only]

このプロパティは、フォントの読み込み状態を表します。以下のいずれかの値をとります。

定数説明
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' }

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