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

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