Question

I need that case of QLineEdit was always lower. I will use it with russian letters.

Was it helpful?

Solution

You could simply apply the "toLower" principle, albeit not for QString as that is always handled with "C" locale, but QLocale as per Qt documentation:

QString QLocale::toLower(const QString & str) const

Returns a lowercase copy of str. This function was introduced in QtCore 4.8.

You could use QValidator for the QLineEdit as well if you wish (based on your "initial request"):

void QValidator::setLocale(const QLocale & locale)

Sets the locale that will be used for the validator. Unless setLocale has been called, the validator will use the default locale set with QLocale::setDefault(). If a default locale has not been set, it is the operating system's locale.

and:

State QValidator::validate(QString & input, int & pos) const [pure virtual]

This virtual function returns Invalid if input is invalid according to this validator's rules, Intermediate if it is likely that a little more editing will make the input acceptable (e.g. the user types "4" into a widget which accepts integers between 10 and 99), and Acceptable if the input is valid. The function can change both input and pos (the cursor position) if required.

Once you have your own validator implementation, you can use the following setter of QLineEdit to actually use your validation:

void QLineEdit::setValidator(const QValidator * v)

Sets this line edit to only accept input that the validator, v, will accept. This allows you to place any arbitrary constraints on the text which may be entered. If v == 0, setValidator() removes the current input validator. The initial setting is to have no input validator (i.e. any input is accepted up to maxLength()).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top