このページでは

Qt Quick テキスト入力の処理とバリデータ

テキストの表示タイプ

Qt Quick には、画面上にテキストを表示するためのいくつかのタイプが用意されています。「Text 」タイプは書式設定されたテキストを画面上に表示し、「TextEdit 」タイプは複数行のラインエディットを画面上に配置し、「TextInput 」は編集可能な単一行フィールドを画面上に配置します。

それぞれの具体的な機能やプロパティについて詳しくは、各ドキュメントを参照してください。

入力テキストの検証

バリデータ型は、TextInput オブジェクトの型と形式を強制します。

DoubleValidator

整数以外の数値用のバリデータ定義

IntValidator

整数値用のバリデータを定義します

RegularExpressionValidator

文字列バリデータを提供します

Column {
    spacing: 10

    Text {
        text: "Enter a value from 0 to 2000"
    }
    TextInput {
        focus: true
        validator: IntValidator { bottom:0; top: 2000}
    }
}

バリデータ型は、TextInput のvalidator プロパティにバインドされます。

Column {
    spacing: 10

    Text {
        text: "Which basket?"
    }
    TextInput {
        focus: true
        validator: RegularExpressionValidator { regularExpression: /fruit basket/ }
    }
}

スニペット内の正規表現は、入力されたテキストがfruit basket である場合にのみ許可します。

QML は JavaScript の正規表現を解析しますが、Qt のQRegularExpression クラスの正規表現は Perl の正規表現に基づいていることに注意してください。

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