Qt入门-QLineEdit::setInputMask()

    QLineEdit::setInputMask(const QString & inputMask)方法可以使Edit控件只允许输入自定义的格式字符串,inputMask参数设置格式化字符串的掩码。

inputMask可以是下列字符的组合

Character	Meaning
A

ASCII alphabetic character required. A-Z, a-z.

a

ASCII alphabetic character permitted but not required.

N

ASCII alphanumeric character required. A-Z, a-z, 0-9.

n

ASCII alphanumeric character permitted but not required.

X

Any character required.

x

Any character permitted but not required.

9

ASCII digit required. 0-9.

0

ASCII digit permitted but not required.

D

ASCII digit required. 1-9.

d

ASCII digit permitted but not required (1-9).

#

ASCII digit or plus/minus sign permitted but not required.

H

Hexadecimal character required. A-F, a-f, 0-9.

h

Hexadecimal character permitted but not required.

B

Binary character required. 0-1.

b

Binary character permitted but not required.

>

All following alphabetic characters are uppercased.

<

All following alphabetic characters are lowercased.

!

Switch off case conversion.

\

Use \ to escape the special characters listed above to use them as separators.

示例:

000.000.000.000;”是一个IP地址。

“HH:HH:HH:HH:HH:HH;0”是一个MAC地址。

“\\0\\xHHHH;0”是只允许输入一个16位的十六进制数。

 

另外,一个很有用的技巧是组合使用QLineEdit::setInputMask和QLineEdit::setValidator可实现更复杂的输入屏蔽和验证。


 

你可能感兴趣的:(Qt入门-QLineEdit::setInputMask())