1. 程式人生 > >Qt設定密碼輸入框格式QLineEdit

Qt設定密碼輸入框格式QLineEdit

QLineEdit類自帶public function :  void setEchoMode(EchoMode)   以實現密碼輸入框效果。

我特意看了一下QTextEdit,並沒有這個方法

voidsetEchoMode(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顯示效果: