整个窗口如图所示

先看下界面:
总体上框架使用QGridLayout布局,共5个GroupBox,每个GroupBox内部依旧使用QGridLayout布局,一个QLabel,如Mode:,一个QComboBox,如PasswordEchoOnEdit,一个QLineEdit,显示粗点的那个Echo即为GroupBox的标题,这样整个界面就设置OK了,非常简单,也十分美观

再说下功能:
5各QGroupBox分别对应5各方面的功能,也同时对应着QLineEidt的5个函数
从第一个开始说起:
显示方面的,看下类里面自定义的枚举,正好对应Echo 的ComboxBox的4个选项

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 asterisks instead of the characters actually entered.
QLineEdit::PasswordEchoOnEdit 3 Display characters as they are entered while editing otherwise display asterisks.
使用的函数是:
void setEchoMode ( EchoMode )
相关的函数查了下还有这两个
1.displayText : const QString
This property holds the displayed text.

If echoMode is Normal this returns the same as text(); if EchoMode is Password or PasswordEchoOnEdit it returns a string of asterisks text().length() characters long, e.g. "******"; if EchoMode is NoEcho returns an empty string, "".

By default, this property contains an empty string.
2.text : QString
This property holds the line edit's text.

Setting this property clears the selection, clears the undo/redo history, moves the cursor to the end of the line and resets the modified property to false. The text is not validated when inserted with setText().

The text is truncated to maxLength() length.

By default, this property contains an empty string.
顾名思义,displayText返回的是显示内容,如果时密码模式,那么返回**************星号
第二个:
Validator使用的函数是
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()).

See also validator(), QIntValidator, QDoubleValidator, and QRegExpValidator.
看下程序里是怎么用的
     case 0:
         validatorLineEdit->setValidator(0);
         break;
     case 1:
         validatorLineEdit->setValidator(new QIntValidator(
             validatorLineEdit));
         break;
     case 2:
         validatorLineEdit->setValidator(new QDoubleValidator(-999.0,
             999.0, 2, validatorLineEdit));
     }
是QLineEdit内只能输入整数,0.01精度浮点数。可以看到还可以利用正则控制输入的内容:
QRegExp rx("\\d{,6}");
validatorLineEdit->setValidator(new QRegExpValidator(rx,validatorLineEdit));
这样就只能输入最多6各数字了,再配合前面的密码模式输入就可以用来设置密码了:)
第三个:设置对齐方式
第三各用到的函数是
void setAlignment ( Qt::Alignment flag )
alignment : Qt::Alignment
This property holds the alignment of the line edit.

Both horizontal and vertical alignment is allowed here, Qt::AlignJustify will map to Qt::AlignLeft.

By default, this property contains a combination of Qt::AlignLeft and Qt::AlignVCenter.
非常简单,直接看枚举的类型
enum Qt::AlignmentFlag
flags Qt::Alignment

This enum type is used to describe alignment. It contains horizontal and vertical flags that can be combined to produce the required effect.

The TextElideMode enum can also be used in many situations to fine-tune the appearance of aligned text.

The horizontal flags are:

Constant Value Description
Qt::AlignLeft 0x0001 Aligns with the left edge.
Qt::AlignRight 0x0002 Aligns with the right edge.
Qt::AlignHCenter 0x0004 Centers horizontally in the available space.
Qt::AlignJustify 0x0008 Justifies the text in the available space.
The vertical flags are:

Constant Value Description
Qt::AlignTop 0x0020 Aligns with the top.
Qt::AlignBottom 0x0040 Aligns with the bottom.
Qt::AlignVCenter 0x0080 Centers vertically in the available space.
You can use only one of the horizontal flags at a time. There is one two-dimensional flag:

Constant Value Description
Qt::AlignCenter AlignVCenter | AlignHCenter Centers in both dimensions.
You can use at most one horizontal and one vertical flag at a time. Qt::AlignCenter counts as both horizontal and vertical.

Three enum values are useful in applications that can be run in right-to-left mode:

Constant Value Description
Qt::AlignAbsolute 0x0010 If the widget's layout direction is Qt::RightToLeft (instead of Qt::LeftToRight, the default), Qt::AlignLeft refers to the right edge and Qt::AlignRight to the left edge. This is normally the desired behavior. If you want Qt::AlignLeft to always mean "left" and Qt::AlignRight to always mean "right", combine the flag with Qt::AlignAbsolute.
Qt::AlignLeading AlignLeft Synonym for Qt::AlignLeft.
Qt::AlignTrailing AlignRight Synonym for Qt::AlignRight.
Masks:

Constant Value
Qt::AlignHorizontal_Mask AlignLeft | AlignRight | AlignHCenter | AlignJustify | AlignAbsolute
Qt::AlignVertical_Mask AlignTop | AlignBottom | AlignVCenter
Conflicting combinations of flags have undefined meanings.

The Alignment type is a typedef for QFlags<AlignmentFlag>. It stores an OR combination of AlignmentFlag values.

第四个:可以用来控制一些输入格式,可以无须借助正则
用到函数主要是
void setInputMask ( const QString & inputMask )

直接看介绍
inputMask : QString
This property holds the validation input mask.

If no mask is set, inputMask() returns an empty string.

Sets the QLineEdit's validation mask. Validators can be used instead of, or in conjunction with masks; see setValidator().

Unset the mask and return to normal QLineEdit operation by passing an empty string ("") or just calling setInputMask() with no arguments.

The table below shows the characters that can be used in an input mask. A space character, the default character for a blank, is needed for cases where a character is permitted but not required.

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.
The mask consists of a string of mask characters and separators, optionally followed by a semicolon and the character used for blanks. The blank characters are always removed from the text after editing.

Examples:

Mask Notes
000.000.000.000;_ IP address; blanks are _.
HH:HH:HH:HH:HH:HH;_ MAC address
0000-00-00 ISO Date; blanks are space
>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# License number; blanks are - and all (alphabetic) characters are converted to uppercase.
To get range control (e.g., for an IP address) use masks together with validators.

Access functions:

QString inputMask () const
void setInputMask ( const QString & inputMask )
See also maxLength.
看下程序用到的地方:
    switch (index) {
    case 0:
        inputMaskLineEdit->setInputMask("");
        break;
    case 1:
        inputMaskLineEdit->setInputMask("+99 99 99 99 99;_");
        break;
    case 2:
        inputMaskLineEdit->setInputMask("0000-00-00");
        inputMaskLineEdit->setText("00000000");
        inputMaskLineEdit->setCursorPosition(0);
        break;
    case 3:
        inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
其中分号后面跟的符号会代替掉前面的那些通配符
比如选到License Key ,QLIneEdit内容变为
#####-#####-#####-#####-#####
输入时只能输入字母,同时-会自动跳过,不可改变,不被删除,总之试下就知道了哈哈

5.
很简单,设置内容是否可更改
readOnly : bool
This property holds whether the line edit is read only.

In read-only mode, the user can still copy the text to the clipboard, or drag and drop the text (if echoMode() is Normal), but cannot edit it.

QLineEdit does not show a cursor in read-only mode.

By default, this property is false.

几个函数组合使用,功能很强大