Qt设置密码输入框格式QLineEdit


QLineEdit类自带public function :  void setEchoMode(EchoMode)   以实现密码输入框效果。

我特意看了一下QTextEdit,并没有这个方法

void setEchoMode(EchoMode)   文档介绍

This property holds the line edit's echo mode.

The echo mode determines how the text entered in the line edit is displayed (or echoed) to the user.

The most common setting is Normal, in which the text entered by the user is displayed verbatim,

but QLineEdit also supports modes that allow the entered text to be suppressed or obscured: these include NoEcho, Password and PasswordEchoOnEdit.

The widget's display and the ability to copy or drag the text is affected by this setting.

By default, this property is set to Normal.


大概翻译:


这个属性保存的行编辑的回波模式。回声模式决定了该行的编辑输入的文本显示(或回波)给用户。 最常见的设置是正常的,其中由用户输入的文本显示一字不差, 但QLineEdit中还支持其他模式,允许被抑制或模糊输入的文本:包括NOECHO,Password和PasswordEchoOnEdit。 窗口小部件的显示和复制或拖动文本的能力受到此设置的影响。 默认情况下,这个属性被设置为正常。


EchoMode的枚举值

enum QLineEdit::EchoMode
This enum type describes how a line edit should display its contents.

Constant	        Value	        Description
QLineEdit::Normal	0	Display characters as they are entered. This is the default.
                                //正常显示形式,也就是边输入边显示
QLineEdit::NoEcho	1	Do not display anything. This may be appropriate for passwords where 
                                even the length of the password should be kept secret.
                                //不会显示任何字符,包括长度
QLineEdit::Password	2	Display platform-dependent password mask characters instead of 
                                the characters actually entered.
                                //根据平台使用模糊字符代替你实际输入的字符
QLineEdit::PasswordEchoOnEdit 3	Display characters as they are entered while editing 
                                otherwise display characters as with Password.
                                //当你处于输入状态的时候,是正常显示字符。 输入完毕之后
                                //使用Password形式隐藏字符


通过EchoMode提供枚举值有选择的设置setEchoMode(EchoMode),以达到自己想要的效果。


window显示效果:


Qt设置密码输入框格式QLineEdit_第1张图片




你可能感兴趣的:(QT)