c++ - 如何使用带有俄语字母的 QLineEdit 蒙版?

标签 c++ qt qtgui qtcore qlineedit

我需要 QLineEdit 的大小写始终较低。我将把它与俄语字母一起使用。

最佳答案

您可以简单地应用“toLower”原则,尽管不适用于QString,因为它始终使用“C”语言环境处理,但根据Qt文档,QLocale:

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

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

如果您愿意,您也可以将 QValidator 用于 QLineEdit(基于您的“初始请求”):

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.

和:

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.

一旦您拥有自己的验证器实现,您就可以使用以下 QLineEdit setter 来实际使用您的验证:

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()).

关于c++ - 如何使用带有俄语字母的 QLineEdit 蒙版?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19196089/

相关文章:

c++ - 如何使用用户输入的变量来定义另一个变量

c++ - boost 多阵列作为类成员未填充

c++ - 线程化 OpenGL 与 Qt 5.1 共享 QGLWidgets 问题

windows-10 - 我可以在 Ubuntu WSL 中使用 Python QT 开发 GUI 软件吗?

c++ - 来自 HBITMAP 的 QImage

c++ - 如何调用所有基类的析构函数? (或一个共同的功能)

python - 功能无法正常工作

python - PyQt4中如何通过代理发起请求

c++ - 如何使用 qmake 和 MinGW32 在 QtCreator 中链接动态库?

c++ - Qt - 为什么无法使用带有从 FileDialog 获取的目录的 QFile 读取文件?