QLineEdit 类

QLineEdit widget is a one-line text editor. 更多...

头: #include <QLineEdit>
qmake: QT += widgets
继承: QWidget

公共类型

enum ActionPosition { LeadingPosition, TrailingPosition }
enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit }

特性

公共函数

QLineEdit (QWidget * parent = Q_NULLPTR)
QLineEdit (const QString & contents , QWidget * parent = Q_NULLPTR)
~QLineEdit ()
void addAction (QAction * action , ActionPosition position )
QAction * addAction (const QIcon & icon , ActionPosition position )
Qt::Alignment alignment () const
void backspace ()
QCompleter * completer () const
QMenu * createStandardContextMenu ()
void cursorBackward (bool mark , int steps = 1)
void cursorForward (bool mark , int steps = 1)
Qt::CursorMoveStyle cursorMoveStyle () const
int cursorPosition () const
int cursorPositionAt (const QPoint & pos )
void cursorWordBackward (bool mark )
void cursorWordForward (bool mark )
void del ()
void deselect ()
QString displayText () const
bool dragEnabled () const
EchoMode echoMode () const
void end (bool mark )
void getTextMargins (int * left , int * top , int * right , int * bottom ) const
bool hasAcceptableInput () const
bool hasFrame () const
bool hasSelectedText () const
void home (bool mark )
QString inputMask () const
void insert (const QString & newText )
bool isClearButtonEnabled () const
bool isModified () const
bool isReadOnly () const
bool isRedoAvailable () const
bool isUndoAvailable () const
int maxLength () const
QString placeholderText () const
QString selectedText () const
int selectionStart () const
void setAlignment (Qt::Alignment flag )
void setClearButtonEnabled (bool enable )
void setCompleter (QCompleter * c )
void setCursorMoveStyle (Qt::CursorMoveStyle style )
void setCursorPosition ( int )
void setDragEnabled (bool b )
void setEchoMode ( EchoMode )
void setFrame ( bool )
void setInputMask (const QString & inputMask )
void setMaxLength ( int )
void setModified ( bool )
void setPlaceholderText ( const QString & )
void setReadOnly ( bool )
void setSelection (int start , int length )
void setTextMargins (int left , int top , int right , int bottom )
void setTextMargins (const QMargins & margins )
void setValidator (const QValidator * v )
QString text () const
QMargins textMargins () const
const QValidator * validator () const

重实现公共函数

virtual bool event (QEvent * e )
virtual QVariant inputMethodQuery (Qt::InputMethodQuery property ) const
virtual QSize minimumSizeHint () const
virtual QSize sizeHint () const

公共槽

void clear ()
void copy () const
void cut ()
void paste ()
void redo ()
void selectAll ()
void setText ( const QString & )
void undo ()

信号

void cursorPositionChanged (int old , int new )
void editingFinished ()
void returnPressed ()
void selectionChanged ()
void textChanged (const QString & text )
void textEdited (const QString & text )

保护函数

QRect cursorRect () const
void initStyleOption (QStyleOptionFrame * option ) const

重实现保护函数

virtual void changeEvent (QEvent * ev )
virtual void contextMenuEvent (QContextMenuEvent * event )
virtual void dragEnterEvent (QDragEnterEvent * e )
virtual void dragLeaveEvent (QDragLeaveEvent * e )
virtual void dragMoveEvent (QDragMoveEvent * e )
virtual void dropEvent (QDropEvent * e )
virtual void focusInEvent (QFocusEvent * e )
virtual void focusOutEvent (QFocusEvent * e )
virtual void inputMethodEvent (QInputMethodEvent * e )
virtual void keyPressEvent (QKeyEvent * event )
virtual void mouseDoubleClickEvent (QMouseEvent * e )
virtual void mouseMoveEvent (QMouseEvent * e )
virtual void mousePressEvent (QMouseEvent * e )
virtual void mouseReleaseEvent (QMouseEvent * e )
virtual void paintEvent ( QPaintEvent * )

额外继承成员

详细描述

QLineEdit widget is a one-line text editor.

行编辑允许用户键入和编辑单行纯文本,采用有用编辑功能的集合,包括:撤消/重做、剪切/粘贴及拖放 (见 setDragEnabled ()).

通过改变 echoMode () 为行编辑,它还可以用作只写字段 (用于密码之类的输入)。

可以把文本长度约束到 maxLength ()。可以任意约束文本使用 validator () 或 inputMask (),或两者。当在同一行编辑的验证器和输入掩码之间切换时,最好清零验证器或输入掩码,以防未定义行为。

相关类 QTextEdit 允许多行,编辑富文本。

可以改变文本采用 setText () 或 insert ()。文本的检索采用 text ();显示文本 (可能不同,见 EchoMode ) 的检索采用 displayText ()。可以选择文本采用 setSelection () 或 selectAll (), 且选择可以被 cut (), copy () 和 paste ()。可以对齐文本采用 setAlignment ().

当文本改变时 textChanged () 信号被发射;当文本改变时,除了通过调用 setText () textEdited () 信号被发射;当光标移动时 cursorPositionChanged () 信号被发射;而当按下 Return 或 Enter 键时 returnPressed () 信号被发射。

当编辑完成时,由于行编辑失去聚焦或按下 Return/Enter 键 editingFinished () 信号被发射。

注意:若行编辑有设置验证器, returnPressed ()/ editingFinished () 信号才会被发射,若验证器返回 QValidator::Acceptable .

默认情况下,QLineEdit 拥有由平台风格指南指定的框架;可以关闭它通过调用 setFrame (false).

默认键绑定的描述见下文。行编辑还提供上下文菜单 (通常通过鼠标右键援引),呈现这些编辑选项中的一些。

Keypress 动作
Left Arrow 左移光标一字符。
Shift+Left Arrow 左移并选择文本一字符。
Right Arrow 右移光标一字符。
Shift+Right Arrow 右移并选择文本一字符。
首页 把光标移到行开头。
End 把光标移到行尾。
Backspace 删除光标左侧字符。
Ctrl+Backspace 删除光标左侧的单词。
Delete 删除光标右侧字符。
Ctrl+Delete 删除光标右侧的单词。
Ctrl+A 选择所有。
Ctrl+C 把选中文本拷贝到剪贴板。
Ctrl+Insert 把选中文本拷贝到剪贴板。
Ctrl+K 删除到行尾。
Ctrl+V 将剪贴板文本粘贴到行编辑。
Shift+Insert 将剪贴板文本粘贴到行编辑。
Ctrl+X 删除选中文本并把它拷贝到剪贴板。
Shift+Delete 删除选中文本并把它拷贝到剪贴板。
Ctrl+Z 撤消上一操作。
Ctrl+Y 重做上一撤消操作。

表示有效字符的任何其它键序列,将导致该字符被插入行编辑。

另请参阅 QTextEdit , QLabel , QComboBox , GUI 设计手册:字段、条目 ,和 行编辑范例 .

成员类型文档编制

enum QLineEdit:: ActionPosition

此枚举类型描述行编辑应该如何显示要被添加的动作 Widget。

常量 描述
QLineEdit::LeadingPosition 0 Widget 显示在文本左侧当使用布局方向 Qt::LeftToRight 或右侧当使用 Qt::RightToLeft ,分别。
QLineEdit::TrailingPosition 1 Widget 显示在文本右侧当使用布局方向 Qt::LeftToRight 或左侧当使用 Qt::RightToLeft ,分别。

该枚举在 Qt 5.2 引入或被修改。

另请参阅 addAction (), removeAction (),和 QWidget::layoutDirection .

enum QLineEdit:: EchoMode

此枚举类型描述行编辑应如何显示其内容。

常量 描述
QLineEdit::Normal 0 显示字符如键入它们时。这是默认值。
QLineEdit::NoEcho 1 不显示任何东西。这可能适用于口令 (即使口令长度也应保密)。
QLineEdit::Password 2 显示从属平台的口令掩码字符,而不是实际键入字符。
QLineEdit::PasswordEchoOnEdit 3 显示字符如键入它们当编辑时,否则显示字符如采用 Password .

另请参阅 setEchoMode () 和 echoMode ().

特性文档编制

acceptableInput : const bool

此特性保持输入是否满足 inputMask 和验证器。

默认情况下此特性为 true .

访问函数:

bool hasAcceptableInput () const

另请参阅 setInputMask () 和 setValidator ().

alignment : Qt::Alignment

This property holds the alignment of the line edit

在这里允许水平和垂直对齐, Qt::AlignJustify 将映射到 Qt::AlignLeft .

默认情况下,此特性包含组合的 Qt::AlignLeft and Qt::AlignVCenter .

访问函数:

Qt::Alignment alignment () const
void setAlignment (Qt::Alignment flag )

另请参阅 Qt::Alignment .

clearButtonEnabled : bool

此特性保持行编辑是否显示清零按钮,当它非空时。

若启用,行编辑显示结尾 clear 按钮 (当它包含一些文本时),否则,行编辑不展示清零按钮 (默认)。

该特性在 Qt 5.2 引入。

访问函数:

bool isClearButtonEnabled () const
void setClearButtonEnabled (bool enable )

另请参阅 addAction () 和 removeAction ().

cursorMoveStyle : Qt::CursorMoveStyle

This property holds the movement style of cursor in this line edit

当此特性被设为 Qt::VisualMoveStyle ,行编辑将使用视觉移动样式。按左箭头键将始终导致光标向左移动,不管文本的书写方向。同样的行为适用于右箭头键。

当特性为 Qt::LogicalMoveStyle (默认),在 LTR 文本块中,当按左箭头键时增加光标位置,当按右箭头键时减少光标位置。若文本块是 (RTL) 从右到左,适用相反行为。

该特性在 Qt 4.8 引入。

访问函数:

Qt::CursorMoveStyle cursorMoveStyle () const
void setCursorMoveStyle (Qt::CursorMoveStyle style )

cursorPosition : int

This property holds the current cursor position for this line edit

设置光标位置导致重绘,当适当时。

默认情况下,此特性包含 0 值。

访问函数:

int cursorPosition () const
void setCursorPosition ( int )

displayText : const QString

This property holds the displayed text

echoMode is Normal 这返回如同 text ();若 EchoMode is Password or PasswordEchoOnEdit 它返回字符串对于从属平台的口令掩码字符 text ().length() 按尺寸,如 ******;若 EchoMode is NoEcho 返回 "" 空字符串。

默认情况下,此特性包含空字符串。

访问函数:

QString displayText () const

另请参阅 setEchoMode (), text (),和 EchoMode .

dragEnabled : bool

This property holds whether the lineedit starts a drag if the user presses and moves the mouse on some selected text

拖曳默认禁用。

访问函数:

bool dragEnabled () const
void setDragEnabled (bool b )

echoMode : EchoMode

This property holds the line edit's echo mode

回显模式确定在行编辑中键入的文本,如何显示 (或回显) 给用户。

最常见设置是 Normal ,用户键入的文本逐字显示,但 QLineEdit 还支持允许抑制或遮盖键入文本的模式:这些包括 NoEcho , Password and PasswordEchoOnEdit .

Widget 的显示及拷贝或拖曳文本的能力,受此设置影响。

默认情况下,此特性被设为 Normal .

访问函数:

EchoMode echoMode () const
void setEchoMode ( EchoMode )

另请参阅 EchoMode and displayText ().

frame : bool

This property holds whether the line edit draws itself with a frame

若使行编辑能够 (默认) 在框架内绘制自身,否则,行编辑将绘制自身不用任何框架。

访问函数:

bool hasFrame () const
void setFrame ( bool )

hasSelectedText : const bool

此特性保持是否有选中任何文本。

hasSelectedText() 返回 true 若用户有选中部分或全部文本;否则返回 false .

默认情况下此特性为 false .

访问函数:

bool hasSelectedText () const

另请参阅 selectedText ().

inputMask : QString

This property holds the validation input mask

若未设置掩码,inputMask() 返回空字符串。

设置 QLineEdit 的验证掩码。可以使用验证器代替掩码或与掩码结合;见 setValidator ().

不设置掩码并返回正常 QLineEdit 操作通过传递 "" 空字符串。

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 .

字符 含义
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 必需为十六进制字符,如 A-F、a-f、0-9。
h 准许为十六进制字符,但不是必需的。
B 必需为二进制字符:0-1。
b 准许为二进制字符,但不是必需的。
> 所有之后字母字符大写。
< 所有之后字母字符小写。
! 关闭大小写转换。
[ ] { } 预留。
\ 使用 \ 转义上文列出的特殊字符以将它们用作分隔符。

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.

范例:

掩码 注意事项
000.000.000.000;_ IP 地址;空白为 _ .
HH:HH:HH:HH:HH:HH;_ MAC 地址
0000-00-00 ISO 日期;空白为 space
>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# 许可编号; 空白为 - 且所有 (字母) 字符被转换成大写。

要获得范围控制 (如:IP 地址),使用掩码同 validators .

访问函数:

QString inputMask () const
void setInputMask (const QString & inputMask )

另请参阅 maxLength .

maxLength : int

This property holds the maximum permitted length of the text

若文本太长,则在限制处截取它。

若发生截断,将取消选择任何文本的选定,光标位置设为 0 并展示字符串的第一部分。

若行编辑拥有输入掩码,掩码将定义最大字符串长度。

默认情况下,此特性包含 32767 值。

访问函数:

int maxLength () const
void setMaxLength ( int )

另请参阅 inputMask .

modified : bool

This property holds whether the line edit's contents has been modified by the user

修改标志从不被读取由 QLineEdit ;它拥有默认值 false,且被改为 true 每当用户改变行编辑内容时。

这对需要提供默认值但一开始不知道默认值应该是什么 (或许取决于表单中的其它字段) 的情况,很有用。在没有最佳默认值的情况下开始行编辑,且当默认值已知时,若 modified() 返回 false (用户没有键入任何文本),插入默认值。

调用 setText () 重置修改标志为 false。

访问函数:

bool isModified () const
void setModified ( bool )

placeholderText : QString

This property holds the line edit's placeholder text

设置此特性使行编辑显示变灰占位符文本,只要行编辑为空。

通常,空行编辑展示占位符文本,即使它拥有聚焦。不管怎样,若内容水平居中,占位符文本不会显示在光标下方 (当行编辑拥有聚焦时)。

默认情况下,此特性包含空字符串。

该特性在 Qt 4.7 引入。

访问函数:

QString placeholderText () const
void setPlaceholderText ( const QString & )

另请参阅 text ().

readOnly : bool

此特性保持行编辑是否为只读。

在只读模式下,用户仍可以将文本拷贝到剪贴板,或拖放文本 (若 echoMode () 是 Normal ),但无法编辑它。

QLineEdit 在只读模式下不展示光标。

默认情况下此特性为 false .

访问函数:

bool isReadOnly () const
void setReadOnly ( bool )

另请参阅 setEnabled ().

redoAvailable : const bool

This property holds whether redo is available

重做变为可用,一旦用户对行编辑中的文本有履行一次或多次撤消操作。

默认情况下此特性为 false .

访问函数:

bool isRedoAvailable () const

selectedText : const QString

此特性保持选中文本

若没有选中文本,此特性的值为空字符串。

默认情况下,此特性包含空字符串。

访问函数:

QString selectedText () const

另请参阅 hasSelectedText ().

text : QString

This property holds the line edit's text

设置此特性清零选定,清零撤消/重做历史,把光标移至行尾并重置 modified 特性为 false。文本不验证,当采用 setText() 插入时。

文本被截取到 maxLength () 长度。

默认情况下,此特性包含空字符串。

访问函数:

QString text () const
void setText ( const QString & )

通知程序信号:

void textChanged (const QString & text )

另请参阅 insert () 和 clear ().

undoAvailable : const bool

This property holds whether undo is available

撤消变为可用,一旦用户有修改行编辑文本。

默认情况下此特性为 false .

访问函数:

bool isUndoAvailable () const

成员函数文档编制

QLineEdit:: QLineEdit ( QWidget * parent = Q_NULLPTR)

构造行编辑不采用文本。

最大文本长度被设为 32767 个字符。

parent 自变量被发送给 QWidget 构造函数。

另请参阅 setText () 和 setMaxLength ().

QLineEdit:: QLineEdit (const QString & contents , QWidget * parent = Q_NULLPTR)

构造行编辑包含文本 contents .

光标位置被设为行尾,且最大文本长度被设为 32767 个字符。

parent 和自变量被发送给 QWidget 构造函数。

另请参阅 text () 和 setMaxLength ().

QLineEdit:: ~QLineEdit ()

销毁行编辑。

void QLineEdit:: addAction ( QAction * action , ActionPosition position )

这是重载函数。

添加 action 到动作列表在 position .

该函数在 Qt 5.2 引入。

QAction *QLineEdit:: addAction (const QIcon & icon , ActionPosition position )

这是重载函数。

创建新的动作采用给定 icon position .

该函数在 Qt 5.2 引入。

void QLineEdit:: backspace ()

若未选择文本,删除文本光标左侧字符并左移光标一位置。若有选择任何文本,光标将移动到选定文本的开头并删除所选文本。

另请参阅 del ().

[virtual protected] void QLineEdit:: changeEvent ( QEvent * ev )

重实现自 QWidget::changeEvent ().

[slot] void QLineEdit:: clear ()

清零行编辑的内容。

另请参阅 setText () 和 insert ().

QCompleter *QLineEdit:: completer () const

返回当前 QCompleter ,其提供补全。

该函数在 Qt 4.2 引入。

另请参阅 setCompleter ().

[virtual protected] void QLineEdit:: contextMenuEvent ( QContextMenuEvent * event )

重实现自 QWidget::contextMenuEvent ().

展示标准上下文菜单,创建采用 createStandardContextMenu ().

若不希望行编辑拥有上下文菜单,可以设置它的 contextMenuPolicy to Qt::NoContextMenu 。若想要定制上下文菜单,重实现此函数。若想要扩展标准上下文菜单,重实现此函数,调用 createStandardContextMenu () 并扩展返回的菜单。

void LineEdit::contextMenuEvent(QContextMenuEvent *event)
{
    QMenu *menu = createStandardContextMenu();
    menu->addAction(tr("My Menu Item"));
    //...
    menu->exec(event->globalPos());
    delete menu;
}
					

event 参数用于获取鼠标光标位置,当生成事件时。

另请参阅 setContextMenuPolicy ().

[slot] void QLineEdit:: copy () const

把选中文本拷贝到剪贴板 (若有的话),且若 echoMode () 是 Normal .

另请参阅 cut () 和 paste ().

QMenu *QLineEdit:: createStandardContextMenu ()

此函数创建要展示的标准上下文菜单,当用户采用鼠标右键点击行编辑时。它被调用从默认 contextMenuEvent () 处理程序。弹出菜单的所有权被转移给调用者。

void QLineEdit:: cursorBackward ( bool mark , int steps = 1)

后移光标 steps 字符。若 mark 为 true,每个移过字符会被添加到选定;若 mark 为 False,清零选定。

另请参阅 cursorForward ().

void QLineEdit:: cursorForward ( bool mark , int steps = 1)

前移光标 steps 字符。若 mark 为 true,每个移过字符会被添加到选定;若 mark 为 False,清零选定。

另请参阅 cursorBackward ().

int QLineEdit:: cursorPositionAt (const QPoint & pos )

返回光标位置在点 pos .

[signal] void QLineEdit:: cursorPositionChanged ( int old , int new )

此信号被发射每当光标移动时。先前位置被给定由 old ,和新位置由 new .

另请参阅 setCursorPosition () 和 cursorPosition ().

[protected] QRect QLineEdit:: cursorRect () const

返回包括行编辑光标的矩形。

该函数在 Qt 4.4 引入。

void QLineEdit:: cursorWordBackward ( bool mark )

将光标后移一单词。若 mark 为 true,单词还被选中。

另请参阅 cursorWordForward ().

void QLineEdit:: cursorWordForward ( bool mark )

将光标前移一单词。若 mark 为 true,单词还被选中。

另请参阅 cursorWordBackward ().

[slot] void QLineEdit:: cut ()

把选中文本拷贝到剪贴板且删除它 (若有的话),且若 echoMode () 是 Normal .

若当前验证器禁止删除选中文本,cut() 将拷贝而不删除。

另请参阅 copy (), paste (),和 setValidator ().

void QLineEdit:: del ()

若未选择文本,删除文本光标右侧字符。若有选择任何文本,光标将移动到选定文本的开头并删除所选文本。

另请参阅 backspace ().

void QLineEdit:: deselect ()

取消任何选中文本的选择。

另请参阅 setSelection () 和 selectAll ().

[virtual protected] void QLineEdit:: dragEnterEvent ( QDragEnterEvent * e )

重实现自 QWidget::dragEnterEvent ().

[virtual protected] void QLineEdit:: dragLeaveEvent ( QDragLeaveEvent * e )

重实现自 QWidget::dragLeaveEvent ().

[virtual protected] void QLineEdit:: dragMoveEvent ( QDragMoveEvent * e )

重实现自 QWidget::dragMoveEvent ().

[virtual protected] void QLineEdit:: dropEvent ( QDropEvent * e )

重实现自 QWidget::dropEvent ().

[signal] void QLineEdit:: editingFinished ()

此信号被发射当 Return/Enter 键被按下或行编辑丢失聚焦时。注意:若有 validator () 或 inputMask () 设置在行编辑且 Enter/Return 键被按下,editingFinished() 信号才会被发射,若输入紧跟 inputMask () 和 validator () 返回 QValidator::Acceptable .

void QLineEdit:: end ( bool mark )

将光标移至行末尾,除非光标已移到那里。若 mark 为 true,选择文本到最后位置;否则,取消选择任何文本的选定若光标被移动。

另请参阅 home ().

[virtual] bool QLineEdit:: event ( QEvent * e )

重实现自 QObject::event ().

[virtual protected] void QLineEdit:: focusInEvent ( QFocusEvent * e )

重实现自 QWidget::focusInEvent ().

[virtual protected] void QLineEdit:: focusOutEvent ( QFocusEvent * e )

重实现自 QWidget::focusOutEvent ().

void QLineEdit:: getTextMargins ( int * left , int * top , int * right , int * bottom ) const

Returns the widget's text margins for left , top , right ,和 bottom .

该函数在 Qt 4.5 引入。

另请参阅 setTextMargins ().

void QLineEdit:: home ( bool mark )

将光标移至行开头,除非光标已移到那里。若 mark 为 true,选择文本到第一位置;否则,取消选择任何文本的选定若光标被移动。

另请参阅 end ().

[protected] void QLineEdit:: initStyleOption ( QStyleOptionFrame * option ) const

初始化 option 采用值来自此 QLineEdit 。此方法对子类是有用的,当需要 QStyleOptionFrame ,但不希望自己填充所有信息。

另请参阅 QStyleOption::initFrom ().

[virtual protected] void QLineEdit:: inputMethodEvent ( QInputMethodEvent * e )

重实现自 QWidget::inputMethodEvent ().

[virtual] QVariant QLineEdit:: inputMethodQuery ( Qt::InputMethodQuery property ) const

重实现自 QWidget::inputMethodQuery ().

void QLineEdit:: insert (const QString & newText )

删除任何选中文本,插入 newText ,并验证结果。若有效,则将其设为行编辑的新内容。

另请参阅 setText () 和 clear ().

[virtual protected] void QLineEdit:: keyPressEvent ( QKeyEvent * event )

重实现自 QWidget::keyPressEvent ().

转换给定键按下 event 成行编辑动作。

若 Return 或 Enter 键被按下且当前文本有效 (或可以是 使有效 通过验证器),信号 returnPressed () 被发射。

默认键绑定列表在类的详细描述中。

[virtual] QSize QLineEdit:: minimumSizeHint () const

重实现自 QWidget::minimumSizeHint ().

返回行编辑最小尺寸。

The width returned is enough for at least one character.

[virtual protected] void QLineEdit:: mouseDoubleClickEvent ( QMouseEvent * e )

重实现自 QWidget::mouseDoubleClickEvent ().

[virtual protected] void QLineEdit:: mouseMoveEvent ( QMouseEvent * e )

重实现自 QWidget::mouseMoveEvent ().

[virtual protected] void QLineEdit:: mousePressEvent ( QMouseEvent * e )

重实现自 QWidget::mousePressEvent ().

[virtual protected] void QLineEdit:: mouseReleaseEvent ( QMouseEvent * e )

重实现自 QWidget::mouseReleaseEvent ().

[virtual protected] void QLineEdit:: paintEvent ( QPaintEvent * )

重实现自 QWidget::paintEvent ().

[slot] void QLineEdit:: paste ()

将剪贴板文本插入在光标位置处,删除任何选中文本,若行编辑不为 只读 .

If the end result would not be acceptable to the current validator ,什么都不发生。

另请参阅 copy () 和 cut ().

[slot] void QLineEdit:: redo ()

重做上一操作,若重做 available .

[signal] void QLineEdit:: returnPressed ()

此信号被发射,当 Return 或 Enter 键被按下。注意, 若存在 validator () 或 inputMask () 设置在行编辑,returnPressed() 信号才会被发射若输入跟随 inputMask () 和 validator () 返回 QValidator::Acceptable .

[slot] void QLineEdit:: selectAll ()

选择所有文本 (即:突显文本) 并将光标移至末尾。这很有用当插入默认值时,因为若用户在点击 Widget 之前键入,则选中文本会被删除。

另请参阅 setSelection () 和 deselect ().

[signal] void QLineEdit:: selectionChanged ()

此信号被发射每当选定改变时。

另请参阅 hasSelectedText () 和 selectedText ().

int QLineEdit:: selectionStart () const

返回行编辑第一选中字符的索引,或 -1 若没有文本被选中。

另请参阅 selectedText ().

void QLineEdit:: setCompleter ( QCompleter * c )

将为此行编辑提供自动补全的补全器设为 c 。补全模式的设置使用 QCompleter::setCompletionMode ().

要使用 QCompleter 采用 QValidator or QLineEdit::inputMask ,需要确保模型被提供给 QCompleter 包含有效条目。可以使用 QSortFilterProxyModel 以确保 QCompleter 的模型只包含有效条目。

c == 0,setCompleter() 将移除当前补全器,有效禁用自动补全。

该函数在 Qt 4.2 引入。

另请参阅 completer () 和 QCompleter .

void QLineEdit:: setSelection ( int start , int length )

选择文本从位置 start 和对于 length 个字符。负长度是允许的。

另请参阅 deselect (), selectAll (),和 selectedText ().

void QLineEdit:: setTextMargins ( int left , int top , int right , int bottom )

将框架围绕文本的边距尺寸设为 left , top , right ,和 bottom .

另请参阅 getTextMargins ().

该函数在 Qt 4.5 引入。

另请参阅 textMargins ().

void QLineEdit:: setTextMargins (const QMargins & margins )

设置 margins 围绕文本在框架内。

另请参阅 textMargins ().

该函数在 Qt 4.6 引入。

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.

v == 0,setValidator() 将移除当前输入验证器。初始设置没有输入验证器 (即:接受任何输入最多 maxLength ()).

另请参阅 validator (), hasAcceptableInput (), QIntValidator , QDoubleValidator ,和 QRegExpValidator .

[virtual] QSize QLineEdit:: sizeHint () const

重实现自 QWidget::sizeHint ().

返回 Widget 的推荐尺寸。

返回宽度 (以像素为单位),通常够大约 15 到 20 个字符。

[signal] void QLineEdit:: textChanged (const QString & text )

此信号被发射每当文本改变时。 text 自变量是新文本。

不像 textEdited (),此信号也会被发射,当文本以编程方式被改变时,例如:通过调用 setText ().

注意: 通知程序信号对于特性 text .

[signal] void QLineEdit:: textEdited (const QString & text )

此信号被发射每当文本被编辑。 text 自变量是新文本。

不像 textChanged (),此信号不被发射,当文本以编程方式被改变时,例如:通过调用 setText ().

QMargins QLineEdit:: textMargins () const

返回 Widget 的文本边距。

该函数在 Qt 4.6 引入。

另请参阅 setTextMargins ().

[slot] void QLineEdit:: undo ()

撤消上一操作,若撤消 available 。取消当前任何选定,并将选择起始更新成当前光标位置。

const QValidator *QLineEdit:: validator () const

Returns a pointer to the current input validator, or 0 if no validator has been set.

另请参阅 setValidator ().