QLineEdit Class Reference

[QtGui module]

在QLineEdit中widget是一个单行的文本编辑器。More…

继承QWidget

Types

  • enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit }

Methods

  • __init__ (self, QWidget parent = None)
  • __init__ (self, QString contents, QWidget parent = None)
  • Qt.Alignment alignment (self)
  • backspace (self)
  • changeEvent (self, QEvent)
  • clear (self)
  • QCompleter completer (self)
  • contextMenuEvent (self, QContextMenuEvent)
  • copy (self)
  • QMenu createStandardContextMenu (self)
  • cursorBackward (self, bool mark, int steps = 1)
  • cursorForward (self, bool mark, int steps = 1)
  • Qt.CursorMoveStyle cursorMoveStyle (self)
  • int cursorPosition (self)
  • int cursorPositionAt (self, QPoint pos)
  • QRect cursorRect (self)
  • cursorWordBackward (self, bool mark)
  • cursorWordForward (self, bool mark)
  • cut (self)
  • del_ (self)
  • deselect (self)
  • QString displayText (self)
  • bool dragEnabled (self)
  • dragEnterEvent (self, QDragEnterEvent)
  • dragLeaveEvent (self, QDragLeaveEvent e)
  • dragMoveEvent (self, QDragMoveEvent e)
  • dropEvent (self, QDropEvent)
  • EchoMode echoMode (self)
  • end (self, bool mark)
  • bool event (self, QEvent)
  • focusInEvent (self, QFocusEvent)
  • focusOutEvent (self, QFocusEvent)
  • (int left, int top, int right, int bottom) getTextMargins (self)
  • bool hasAcceptableInput (self)
  • bool hasFrame (self)
  • bool hasSelectedText (self)
  • home (self, bool mark)
  • initStyleOption (self, QStyleOptionFrame option)
  • QString inputMask (self)
  • inputMethodEvent (self, QInputMethodEvent)
  • QVariant inputMethodQuery (self, Qt.InputMethodQuery)
  • insert (self, QString)
  • bool isModified (self)
  • bool isReadOnly (self)
  • bool isRedoAvailable (self)
  • bool isUndoAvailable (self)
  • keyPressEvent (self, QKeyEvent)
  • int maxLength (self)
  • QSize minimumSizeHint (self)
  • mouseDoubleClickEvent (self, QMouseEvent)
  • mouseMoveEvent (self, QMouseEvent)
  • mousePressEvent (self, QMouseEvent)
  • mouseReleaseEvent (self, QMouseEvent)
  • paintEvent (self, QPaintEvent)
  • paste (self)
  • QString placeholderText (self)
  • redo (self)
  • selectAll (self)
  • QString selectedText (self)
  • int selectionStart (self)
  • setAlignment (self, Qt.Alignment flag)
  • setCompleter (self, QCompleter completer)
  • setCursorMoveStyle (self, Qt.CursorMoveStyle style)
  • setCursorPosition (self, int)
  • setDragEnabled (self, bool b)
  • setEchoMode (self, EchoMode)
  • setFrame (self, bool)
  • setInputMask (self, QString inputMask)
  • setMaxLength (self, int)
  • setModified (self, bool)
  • setPlaceholderText (self, QString)
  • setReadOnly (self, bool)
  • setSelection (self, int, int)
  • setText (self, QString)
  • setTextMargins (self, int left, int top, int right, int bottom)
  • setTextMargins (self, QMargins margins)
  • setValidator (self, QValidator)
  • QSize sizeHint (self)
  • QString text (self)
  • QMargins textMargins (self)
  • undo (self)
  • QValidator validator (self)

Qt Signals

  • void cursorPositionChanged (int,int)
  • void editingFinished ()
  • void returnPressed ()
  • void selectionChanged ()
  • void textChanged (const QString&)
  • void textEdited (const QString&)

Detailed Description

在QLineEdit中widget是一个单行的文本编辑器。

A线编辑允许用户输入和编辑纯文本单行与编辑功能,包括撤销和重做,剪切和粘贴,拖放一个有用的集合。

通过改变echoMode()一个行编辑的,它也可以被用来作为“只写”字段,用于输入密码等。

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

一个相关的类是QTextEdit它允许多行,富文本编辑。

您可以更改文本setText()或insert( ) 。全文检索与text();显示的文本(其可以是不同的,见EchoMode)检索与displayText( ) 。文本可以与被选择setSelection()或selectAll() ,并且选择可以是cut( )copy( )灭蝇灯和paste( )D 。文本可与对齐setAlignment( ) 。

当文本改变textChanged( )信号被发射,当文本的变化快于通过呼叫其他setText( )的textEdited()信号被发射,当光标被移动的cursorPositionChanged( )信号被发射,而当回车键按下returnPressed()信号被发射。

当编辑完成,要么是因为该行的编辑失去焦点或Return / Enter键被按下editingFinished()信号被发射。

需要注意的是,如果有一个验证器就行了编辑设置,returnPressed()/editingFinished()信号将只被发射,如果验证器返回QValidator.Acceptable

默认情况下, QLineEdits必须由指定的Windows和Motif风格指南的框架,你可以通过调用的setFrame (假)将其关闭。

默认键绑定描述如下。该行编辑亦规定,提出了一些的这些编辑选项的上下文菜单(通常由单击鼠标右键调用)。

Keypress Action
Left Arrow Moves the cursor one character to the left.
Shift+Left Arrow Moves and selects text one character to the left.
Right Arrow Moves the cursor one character to the right.
Shift+Right Arrow Moves and selects text one character to the right.
Home Moves the cursor to the beginning of the line.
End Moves the cursor to the end of the line.
Backspace Deletes the character to the left of the cursor.
Ctrl+Backspace Deletes the word to the left of the cursor.
Delete Deletes the character to the right of the cursor.
Ctrl+Delete Deletes the word to the right of the cursor.
Ctrl+A Select all.
Ctrl+C Copies the selected text to the clipboard.
Ctrl+Insert Copies the selected text to the clipboard.
Ctrl+K Deletes to the end of the line.
Ctrl+V Pastes the clipboard text into line edit.
Shift+Insert Pastes the clipboard text into line edit.
Ctrl+X Deletes the selected text and copies it to the clipboard.
Shift+Delete Deletes the selected text and copies it to the clipboard.
Ctrl+Z Undoes the last operation.
Ctrl+Y Redoes the last undone operation.

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

| Screenshot of a Macintosh style line edit | A line edit shown in the Macintosh widget style. | | Screenshot of a Windows XP style line edit | A line edit shown in the Windows XP widget style. | | Screenshot of a Plastique style line edit | A line edit shown in the Plastique widget style. |


Type Documentation

  1. QLineEdit.EchoMode

该枚举类型描述了一个行编辑应该如何显示其内容。

Constant Value Description
QLineEdit.Normal 0 显示字符以它们输入。这是默认的。
QLineEdit.NoEcho 1 不显示任何信息。这可能是适当的密码,其中的密码,即使是长度应当保密。
QLineEdit.Password 2 显示星号而不是实际输入的字符。
QLineEdit.PasswordEchoOnEdit 3 因为他们进入编辑时,否则显示星号显示字符。

See also setEchoMode()和echoMode( ) 。


Method Documentation

  1. QLineEdit.__init__ (self, QWidget parent = None)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个行编辑,没有文字。

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

parent参数被发送到QWidget构造函数。

See also setText()和setMaxLength( ) 。

  1. QLineEdit.__init__ (self, QString contents, QWidget parent = None)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个包含文本行编辑contents

光标的位置被设置为一行的末尾和最大文本长度,以32767个字符。

parent和参数发送到QWidget构造函数。

See also text()和setMaxLength( ) 。

  1. Qt.Alignment QLineEdit.alignment (self)

[

  1. QLineEdit.backspace (self)

如果没有文本被选中,删除的字符文本光标的左边,光标移动一个位置到左边。如果有任何文字被选中,将光标移动到所选文本的开头和选定的文本被删除。

]($docs-index.htm)

See also del_( ) 。

  1. QLineEdit.changeEvent (self, QEvent)

从重新实现QWidget.changeEvent( ) 。

  1. QLineEdit.clear (self)

清除行编辑的内容。

See also setText()和insert( ) 。

  1. QCompleter QLineEdit.completer (self)

返回当前QCompleter提供完井。

这个函数中引入了Qt 4.2中。

See also setCompleter( ) 。

  1. QLineEdit.contextMenuEvent (self, QContextMenuEvent)

从重新实现QWidget.contextMenuEvent( ) 。

显示与标准上下文菜单创建createStandardContextMenu( ) 。

如果你不想要的行编辑有一个上下文菜单,可以设置其contextMenuPolicyQt.NoContextMenu。如果你想自定义右键菜单,重新实现这个函数。如果你想扩展标准上下文菜单,重新实现这个函数,调用createStandardContextMenu()和extend菜单返回。

  1. void LineEdit.contextMenuEvent([QContextMenuEvent](qcontextmenuevent.html) *event)
  2. {
  3. [QMenu]($docs-qmenu.html) *menu = createStandardContextMenu();
  4. menu->addAction(tr("My Menu Item"));
  5. //...
  6. menu->exec(event->globalPos());
  7. delete menu;
  8. }

event参数用于获得该鼠标光标是产生事件时的位置。

See also setContextMenuPolicy( ) 。

  1. QLineEdit.copy (self)

将所选文本复制到剪贴板,如果有任何的,如果echoMode()是Normal

See also cut()和paste( ) 。

  1. QMenu QLineEdit.createStandardContextMenu (self)

这个函数创建当用户点击该行编辑用鼠标右键其显示在标准上下文菜单。它是从默认称为contextMenuEvent()处理。在弹出菜单的所有权被传递给调用者。

  1. QLineEdit.cursorBackward (self, bool mark, int steps = 1)

使光标向后移动steps字符。如果mark是真正的每个字符移到被添加到选择,如果mark是假的选择被清除。

See also cursorForward( ) 。

  1. QLineEdit.cursorForward (self, bool mark, int steps = 1)

使光标向前移动steps字符。如果mark是真正的每个字符移到被添加到选择,如果mark是假的选择被清除。

See also cursorBackward( ) 。

  1. Qt.CursorMoveStyle QLineEdit.cursorMoveStyle (self)

[

  1. int QLineEdit.cursorPosition (self)
  1. int QLineEdit.cursorPositionAt (self, QPoint pos)

返回点下的光标位置pos

](qt.html#CursorMoveStyle-enum)

  1. QRect QLineEdit.cursorRect (self)

[

返回包含lineedit光标的矩形。

此功能被引入Qt的4.4 。

  1. QLineEdit.cursorWordBackward (self, bool mark)

向后移动光标一个字。如果mark是真的,这个词也被选中。

]($docs-qrect.html)

See also cursorWordForward( ) 。

  1. QLineEdit.cursorWordForward (self, bool mark)

向前移动光标一个字。如果mark是真的,这个词也被选中。

See also cursorWordBackward( ) 。

  1. QLineEdit.cut (self)

将所选文本复制到剪贴板,然后将其删除,如果有任何的,如果echoMode()是Normal

如果当前的验证程序不允许删除选定的文本,切( )将复制而不删除。

See also copy( )paste()和setValidator( ) 。

  1. QLineEdit.del_ (self)

如果没有文本被选中,删除的字符文本光标的右侧。如果有任何文字被选中,将光标移动到所选文本的开头和选定的文本被删除。

See also backspace( ) 。

  1. QLineEdit.deselect (self)

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

See also setSelection()和selectAll( ) 。

  1. QString QLineEdit.displayText (self)
  1. bool QLineEdit.dragEnabled (self)
  1. QLineEdit.dragEnterEvent (self, QDragEnterEvent)

从重新实现QWidget.dragEnterEvent( ) 。

  1. QLineEdit.dragLeaveEvent (self, QDragLeaveEvent e)

从重新实现QWidget.dragLeaveEvent( ) 。

  1. QLineEdit.dragMoveEvent (self, QDragMoveEvent e)

从重新实现QWidget.dragMoveEvent( ) 。

  1. QLineEdit.dropEvent (self, QDropEvent)

从重新实现QWidget.dropEvent( ) 。

  1. EchoMode QLineEdit.echoMode (self)

[

  1. QLineEdit.end (self, bool mark)

将文本光标移动到该行的末尾,除非它已经存在。如果mark诚然,选择文本朝着最后一个位置,否则,任何选定的文本都被取消,如果光标移动。

]($docs-qlineedit.html#EchoMode-enum)

See also home( ) 。

  1. bool QLineEdit.event (self, QEvent)

从重新实现QObject.event( ) 。

  1. QLineEdit.focusInEvent (self, QFocusEvent)

从重新实现QWidget.focusInEvent( ) 。

  1. QLineEdit.focusOutEvent (self, QFocusEvent)

从重新实现QWidget.focusOutEvent( ) 。

  1. (int left, int top, int right, int bottom) QLineEdit.getTextMargins (self)

返回小部件的文本边距lefttoprightbottom

此功能被引入Qt的4.5 。

See also setTextMargins( ) 。

  1. bool QLineEdit.hasAcceptableInput (self)
  1. bool QLineEdit.hasFrame (self)
  1. bool QLineEdit.hasSelectedText (self)
  1. QLineEdit.home (self, bool mark)

将文本光标移动到行的开头,除非它已经存在。如果mark诚然,文本被选中向第一位置,否则,任何选定的文本都被取消,如果光标移动。

See also end( ) 。

  1. QLineEdit.initStyleOption (self, QStyleOptionFrame option)

初始化option与其它的值QLineEdit。当他们需要一个这种方法是有用的子类QStyleOptionFrame or QStyleOptionFrameV2,但不希望在所有的信息填写自己。此功能将检查的版本QStyleOptionFrame并填写了附加价值QStyleOptionFrameV2

See also QStyleOption.initFrom( ) 。

  1. QString QLineEdit.inputMask (self)
  1. QLineEdit.inputMethodEvent (self, QInputMethodEvent)

从重新实现QWidget.inputMethodEvent( ) 。

  1. QVariant QLineEdit.inputMethodQuery (self, Qt.InputMethodQuery)

从重新实现QWidget.inputMethodQuery( ) 。

  1. QLineEdit.insert (self, QString)

删除任何选定的文本,插入newText,并验证其结果。如果它是有效的,但将其设置为行编辑的新内容。

See also setText()和clear( ) 。

  1. bool QLineEdit.isModified (self)
  1. bool QLineEdit.isReadOnly (self)
  1. bool QLineEdit.isRedoAvailable (self)
  1. bool QLineEdit.isUndoAvailable (self)
  1. QLineEdit.keyPressEvent (self, QKeyEvent)

从重新实现QWidget.keyPressEvent( ) 。

给定的按键转换event成一条线编辑操作。

如果Return或Enter键被按下和当前文本是有效的(或可made valid由验证器) ,所述信号returnPressed()被发射。

默认的键绑定列在类的详细说明。

  1. int QLineEdit.maxLength (self)
  1. QSize QLineEdit.minimumSizeHint (self)

从重新实现QWidget.minimumSizeHint( ) 。

返回一个最小尺寸的行编辑。

返回的宽度是足够的至少一个字符。

  1. QLineEdit.mouseDoubleClickEvent (self, QMouseEvent)

从重新实现QWidget.mouseDoubleClickEvent( ) 。

  1. QLineEdit.mouseMoveEvent (self, QMouseEvent)

从重新实现QWidget.mouseMoveEvent( ) 。

  1. QLineEdit.mousePressEvent (self, QMouseEvent)

从重新实现QWidget.mousePressEvent( ) 。

  1. QLineEdit.mouseReleaseEvent (self, QMouseEvent)

从重新实现QWidget.mouseReleaseEvent( ) 。

  1. QLineEdit.paintEvent (self, QPaintEvent)

从重新实现QWidget.paintEvent( ) 。

  1. QLineEdit.paste (self)

在光标位置插入剪贴板中的文本,删除任何选定的文本,提供线路的编辑是不是read-only

如果最终的结果是不能接受的电流validator,没有任何反应。

See also copy()和cut( ) 。

  1. QString QLineEdit.placeholderText (self)
  1. QLineEdit.redo (self)

重做上次操作,如果是重做available

  1. QLineEdit.selectAll (self)

选择所有文本(即突出了它),将光标移动到最后。此时的默认值已经被插入,因为如果用户键入点击插件之前,所选的文本将被删除是有用的。

See also setSelection()和deselect( ) 。

  1. QString QLineEdit.selectedText (self)
  1. int QLineEdit.selectionStart (self)

selectionStart ( )返回行编辑所选的第一个字符或-1的索引,如果没有选定的文本。

See also selectedText( ) 。

  1. QLineEdit.setAlignment (self, Qt.Alignment flag)
  1. QLineEdit.setCompleter (self, QCompleter completer)

设置此行编辑从完成者提供自动补全,c。完成模式设置使用QCompleter.setCompletionMode( ) 。

要使用QCompleterQValidator or QLineEdit.inputMask,你需要确保该模型提供QCompleter包含有效的条目。您可以使用QSortFilterProxyModel以确保该QCompleter的模型只包含有效的条目。

If c== 0 , setCompleter ()删除当前的完成者,有效地禁用自动完成。

这个函数中引入了Qt 4.2中。

See also completer()和QCompleter

  1. QLineEdit.setCursorMoveStyle (self, Qt.CursorMoveStyle style)
  1. QLineEdit.setCursorPosition (self, int)
  1. QLineEdit.setDragEnabled (self, bool b)
  1. QLineEdit.setEchoMode (self, EchoMode)
  1. QLineEdit.setFrame (self, bool)
  1. QLineEdit.setInputMask (self, QString inputMask)
  1. QLineEdit.setMaxLength (self, int)
  1. QLineEdit.setModified (self, bool)
  1. QLineEdit.setPlaceholderText (self, QString)
  1. QLineEdit.setReadOnly (self, bool)
  1. QLineEdit.setSelection (self, int, int)

从位置选择文本startlength字符。消极的长度是允许的。

See also deselect( )selectAll()和selectedText( ) 。

  1. QLineEdit.setText (self, QString)
  1. QLineEdit.setTextMargins (self, int left, int top, int right, int bottom)

围绕设置在框架内的文字边缘有大小lefttoprightbottom

另请参阅getTextMargins( ) 。

此功能被引入Qt的4.5 。

See also textMargins( ) 。

  1. QLineEdit.setTextMargins (self, QMargins margins)

设置margins周围的边框内的文字。

另请参阅textMargins( ) 。

此功能被引入Qt的4.6 。

  1. QLineEdit.setValidator (self, QValidator)

设置此行编辑只接受输入验证器,v,会接受。这使您可以放置在可输入的文字任意的限制。

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

See also validator( )QIntValidatorQDoubleValidatorQRegExpValidator

  1. QSize QLineEdit.sizeHint (self)

从重新实现QWidget.sizeHint( ) 。

返回推荐大小小部件。

宽度回来,以像素为单位,通常是足够的大约15到20个字符。

  1. QString QLineEdit.text (self)
  1. QMargins QLineEdit.textMargins (self)

[

返回小部件的文本利润。

此功能被引入Qt的4.6 。

]($docs-qmargins.html)

See also setTextMargins( ) 。

  1. QLineEdit.undo (self)

撤消上一个操作,如果是撤销available。取消选择当前的选择,并更新选择的开始到当前光标位置。

  1. QValidator QLineEdit.validator (self)

[

返回一个指针,指向当前输入验证器,或者0 ,如果没有验证已定。

]($docs-qvalidator.html)

See also setValidator( ) 。


Qt Signal Documentation

  1. void cursorPositionChanged (int,int)

这是该信号的默认超载。

这个信号被发射时的光标移动。先前的位置由下式给出old,并通过新的位置new

See also setCursorPosition()和cursorPosition( ) 。

  1. void editingFinished ()

这是该信号的默认超载。

这个信号时,回车键被按下或发出的行编辑失去焦点。需要注意的是,如果有一个validator()或inputMask()设定就行编辑和输入/返回键时, editingFinished ()​​信号将只被发射,如果输入如下的inputMask( )和validator()返回QValidator.Acceptable

  1. void returnPressed ()

这是该信号的默认超载。

当回车键被按下时,这个信号被发射。需要注意的是,如果有一个validator()或inputMask( )设置就行了编辑,该returnPressed ( )信号将只如果输入如下发出的inputMask( )和validator()返回QValidator.Acceptable

  1. void selectionChanged ()

这是该信号的默认超载。

这个信号被发射时的选择改变。

See also hasSelectedText()和selectedText( ) 。

  1. void textChanged (const QString&)

这是该信号的默认超载。

这个信号被发射时的文本改变。该text参数是新的文本。

不像textEdited( ) ,这个信号也时发出的文本编程方式改变,例如,通过调用setText( ) 。

  1. void textEdited (const QString&)

这是该信号的默认超载。

这个信号被发射时的文本编辑。该text参数是新的文本。

不像textChanged( ) ,这个信号没有发出时,文本编程方式改变,例如,通过调用setText( ) 。