このページでは

テキストの表示

テキストを表示するには、 Qt Quick モジュールによって「Text」タイプが提供されています。関連する用途については、「TextInput 」および「TextEdit 」タイプが編集可能なテキストコントロールを提供します。完全なHTMLマークアップについては、「Qt WebEngine 」モジュールを参照してください。

テキストの表示と書式設定

QMLでテキストを表示するには、Textアイテムを作成し、textプロパティに表示したいテキストを設定します。これにより、Textアイテムはそのテキストを表示するようになります。

Textアイテムには、テキストブロック全体のスタイルを設定するためのいくつかのプロパティがあります。これには、色、フォントファミリー、フォントサイズ、太字、斜体などが含まれます。プロパティの完全な一覧については、Text 型のドキュメントを参照してください。

Textアイテムでは、マークアップのようなリッチテキストを使用して、テキストの特定のセクションに選択的にスタイルを適用できます。この機能を使用するには、Text::textFormat をText.StyledTextに設定します。詳細については、Text 型のドキュメントを参照してください。

テキストのレイアウト

デフォルトでは、Textは改行が埋め込まれていない限り、テキストを1行で表示します。行を折り返すには、wrapModeプロパティを設定し、折り返しの基準となるテキストの幅を明示的に指定します。 幅または高さが明示的に設定されていない場合、これらのプロパティを読み取ると、テキストのバウンディング矩形のパラメータが返されます(幅または高さを明示的に設定している場合でも、paintedWidth および paintedHeight を使用できます)。これらのパラメータを考慮すれば、Text は他の Item と同様に配置することができます。

サンプルコード

import QtQuick

Item {
    id: root
    width: 480
    height: 320

    Rectangle {
        color: "#272822"
        width: 480
        height: 320
    }

    Column {
        spacing: 20

        Text {
            text: 'I am the very model of a modern major general!'

            // color can be set on the entire element with this property
            color: "yellow"

        }

        Text {
            // For text to wrap, a width has to be explicitly provided
            width: root.width

            // This setting makes the text wrap at word boundaries when it goes
            // past the width of the Text object
            wrapMode: Text.WordWrap

            // You can use \ to escape quotation marks, or to add new lines (\n).
            //  Use \\ to get a \ in the string
            text: 'I am the very model of a modern major general. I\'ve information \
                  vegetable, animal and mineral. I know the kings of england and I \
                  quote the fights historical; from Marathon to Waterloo in order categorical.'

            // color can be set on the entire element with this property
            color: "white"

        }

        Text {
            text: 'I am the very model of a modern major general!'

            // color can be set on the entire element with this property
            color: "yellow"

            // font properties can be set effciently on the whole string at once
            font { family: 'Courier'; pixelSize: 20; italic: true; capitalization: Font.SmallCaps }

        }

        Text {
            // HTML like markup can also be used
            text: '<font color="white">I am the <b>very</b> model of a modern <i>major general</i>!</font>'

            // This could also be written font { pointSize: 14 }. Both syntaxes are valid.
            font.pointSize: 14

            // StyledText format supports fewer tags, but is more efficient than RichText
            textFormat: Text.StyledText
        }
    }
}

タイトル、本文、斜体など、さまざまな書体で表示されるテキスト

国際化とスケーラビリティ

テキストを扱う際、アプリケーションはデバイスの向きや言語設定など、さまざまな要素を考慮する必要があります。

以下のページでは、これらのさまざまなトピックについて詳しく説明しています。

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