user1899020
user1899020

Reputation: 13575

Is there a convenient way to input only one character by some Qt widget?

Is there any convenient way to input one QChar character by some Qt widget? Using QLineEdit need to convert QString to QChar and do some validation? Any char validator?

Upvotes: 0

Views: 575

Answers (2)

bkausbk
bkausbk

Reputation: 2790

Either you should use QLineEdit::setMaxLength() or set a validator with QLineEdit::setValidator();

QRegExpValidator rv = new QRegExpValidator(QRegExp("^.$"));
lineEdit->setValidator(rv);

Upvotes: 2

Frank Osterfeld
Frank Osterfeld

Reputation: 25155

You can use the maxLength property to limit the input to one character:

lineEdit->setMaxLength(1);

For validation beyond that, implement your own QValidator.

Upvotes: 1

Related Questions