IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Qt Quick Text Input Handling and Validators

Text input and validation.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Text Visual Types

Qt Quick provides several types to display text onto the screen. The Text type will display formatted text onto the screen, the TextEdit type will place a multiline line edit onto the screen, and the TextInput will place a single editable line field onto the screen.

To learn more about their specific features and properties, visit their respective documentation.

Validating Input Text

The validator types enforce the type and format of TextInput objects.

 
Sélectionnez
Column {
    spacing: 10

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

The validator types bind to TextInput's validator property.

 
Sélectionnez
Column {
    spacing: 10

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

The regular expression in the snippet will only allow the inputted text to be fruit basket.

Note that QML parses JavaScript regular expressions, while Qt's QRegularExpression class' regular expressions are based on Perl regular expressions.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+