内容表

上一话题

QLayoutItem

下一话题

QListView

QLineEdit

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

Inheritance diagram of PySide2.QtWidgets.QLineEdit

概要

函数

详细描述

../../_images/windows-lineedit.png

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

通过改变 echoMode() of a line edit, it can also be used as a “write-only” field, for inputs such as passwords.

可以把文本长度约束到 maxLength() . The text can be arbitrarily constrained using a validator() or an inputMask() , or both. When switching between a validator and an input mask on the same line edit, it is best to clear the validator or input mask to prevent undefined behavior.

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

可以改变文本采用 setText() or insert() . The text is retrieved with text() ; the displayed text (which may be different, see EchoMode ) 的检索采用 displayText() . Text can be selected with setSelection() or selectAll() , and the selection can be cut() , copy() ied and paste() d. The text can be aligned with setAlignment() .

当文本改变时 textChanged() signal is emitted; when the text changes other than by calling setText() the textEdited() signal is emitted; when the cursor is moved the cursorPositionChanged() signal is emitted; and when the Return or Enter key is pressed the returnPressed() 信号被发射。

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

注意:若行编辑有设置验证器, returnPressed() / editingFinished() signals will only be emitted if the validator returns Acceptable .

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

The default key bindings are described below. The line edit also provides a context menu (usually invoked by a right mouse click) that presents some of these editing options. .. _desc:

Keypress

Action

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

重做上一撤消操作。

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

class QLineEdit ( [ parent=None ] )

QLineEdit(arg__1[, parent=None])

param parent

QWidget

param arg__1

unicode

构造行编辑不采用文本。

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

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

构造行编辑包含文本 contents .

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

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

PySide2.QtWidgets.QLineEdit. ActionPosition

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

常量

描述

QLineEdit.LeadingPosition

Widget 显示在文本左侧当使用布局方向 Qt::LeftToRight 或右侧当使用 Qt::RightToLeft ,分别。

QLineEdit.TrailingPosition

Widget 显示在文本右侧当使用布局方向 Qt::LeftToRight 或左侧当使用 Qt::RightToLeft ,分别。

PySide2.QtWidgets.QLineEdit. EchoMode

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

常量

描述

QLineEdit.Normal

显示字符如键入它们时。这是默认值。

QLineEdit.NoEcho

不显示任何东西。这可能适用于口令 (即使口令长度也应保密)。

QLineEdit.Password

显示从属平台的口令掩码字符,而不是实际键入字符。

QLineEdit.PasswordEchoOnEdit

显示字符如键入它们当编辑时,否则显示字符如采用 Password .

PySide2.QtWidgets.QLineEdit. addAction ( icon , position )
参数
返回类型

QAction

PySide2.QtWidgets.QLineEdit. addAction ( action , position )
参数

添加 action 到动作列表在 position .

PySide2.QtWidgets.QLineEdit. alignment ( )
返回类型

Alignment

另请参阅

setAlignment()

PySide2.QtWidgets.QLineEdit. backspace ( )

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

另请参阅

del()

PySide2.QtWidgets.QLineEdit. clear ( )

清零行编辑的内容。

PySide2.QtWidgets.QLineEdit. completer ( )
返回类型

QCompleter

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

另请参阅

setCompleter()

PySide2.QtWidgets.QLineEdit. copy ( )

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

另请参阅

cut() paste()

PySide2.QtWidgets.QLineEdit. createStandardContextMenu ( )
返回类型

QMenu

此函数创建要展示的标准上下文菜单,当用户采用鼠标右键点击行编辑时。它被调用从默认 contextMenuEvent() handler. The popup menu’s ownership is transferred to the caller.

PySide2.QtWidgets.QLineEdit. cursorBackward ( mark [ , steps=1 ] )
参数
  • mark bool

  • steps int

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

另请参阅

cursorForward()

PySide2.QtWidgets.QLineEdit. cursorForward ( mark [ , steps=1 ] )
参数
  • mark bool

  • steps int

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

另请参阅

cursorBackward()

PySide2.QtWidgets.QLineEdit. cursorMoveStyle ( )
返回类型

CursorMoveStyle

PySide2.QtWidgets.QLineEdit. cursorPosition ( )
返回类型

int

PySide2.QtWidgets.QLineEdit. cursorPositionAt ( pos )
参数

pos QPoint

返回类型

int

返回光标位置在点 pos .

PySide2.QtWidgets.QLineEdit. cursorPositionChanged ( arg__1 , arg__2 )
参数
  • arg__1 int

  • arg__2 int

PySide2.QtWidgets.QLineEdit. cursorRect ( )
返回类型

QRect

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

PySide2.QtWidgets.QLineEdit. cursorWordBackward ( mark )
参数

mark bool

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

PySide2.QtWidgets.QLineEdit. cursorWordForward ( mark )
参数

mark bool

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

PySide2.QtWidgets.QLineEdit. cut ( )

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

If the current validator disallows deleting the selected text, will copy without deleting.

PySide2.QtWidgets.QLineEdit. del_ ( )

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

另请参阅

backspace()

PySide2.QtWidgets.QLineEdit. deselect ( )

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

PySide2.QtWidgets.QLineEdit. displayText ( )
返回类型

unicode

PySide2.QtWidgets.QLineEdit. dragEnabled ( )
返回类型

bool

另请参阅

setDragEnabled()

PySide2.QtWidgets.QLineEdit. echoMode ( )
返回类型

EchoMode

另请参阅

setEchoMode()

PySide2.QtWidgets.QLineEdit. editingFinished ( )
PySide2.QtWidgets.QLineEdit. end ( mark )
参数

mark bool

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

另请参阅

home()

PySide2.QtWidgets.QLineEdit. getTextMargins ( )

注意

此函数被弃用。

使用 textMargins()

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

另请参阅

setTextMargins()

PySide2.QtWidgets.QLineEdit. hasAcceptableInput ( )
返回类型

bool

PySide2.QtWidgets.QLineEdit. hasFrame ( )
返回类型

bool

PySide2.QtWidgets.QLineEdit. hasSelectedText ( )
返回类型

bool

PySide2.QtWidgets.QLineEdit. home ( mark )
参数

mark bool

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

另请参阅

end()

PySide2.QtWidgets.QLineEdit. initStyleOption ( option )
参数

option QStyleOptionFrame

初始化 option 采用值来自此 QLineEdit 。此方法对子类是有用的,当需要 QStyleOptionFrame , but don’t want to fill in all the information themselves.

另请参阅

initFrom()

PySide2.QtWidgets.QLineEdit. inputMask ( )
返回类型

unicode

另请参阅

setInputMask()

PySide2.QtWidgets.QLineEdit. inputMethodQuery ( 特性 , argument )
参数
  • 特性 InputMethodQuery

  • argument – object

返回类型

object

PySide2.QtWidgets.QLineEdit. inputRejected ( )
PySide2.QtWidgets.QLineEdit. insert ( arg__1 )
参数

arg__1 – unicode

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

PySide2.QtWidgets.QLineEdit. isClearButtonEnabled ( )
返回类型

bool

PySide2.QtWidgets.QLineEdit. isModified ( )
返回类型

bool

PySide2.QtWidgets.QLineEdit. isReadOnly ( )
返回类型

bool

PySide2.QtWidgets.QLineEdit. isRedoAvailable ( )
返回类型

bool

PySide2.QtWidgets.QLineEdit. isUndoAvailable ( )
返回类型

bool

PySide2.QtWidgets.QLineEdit. maxLength ( )
返回类型

int

另请参阅

setMaxLength()

PySide2.QtWidgets.QLineEdit. paste ( )

Inserts the clipboard’s text at the cursor position, deleting any selected text, providing the line edit is not 只读 .

若最终结果无效,对当前 validator ,什么都不发生。

另请参阅

copy() cut()

PySide2.QtWidgets.QLineEdit. placeholderText ( )
返回类型

unicode

PySide2.QtWidgets.QLineEdit. redo ( )

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

PySide2.QtWidgets.QLineEdit. returnPressed ( )
PySide2.QtWidgets.QLineEdit. selectAll ( )

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

PySide2.QtWidgets.QLineEdit. selectedText ( )
返回类型

unicode

PySide2.QtWidgets.QLineEdit. selectionChanged ( )
PySide2.QtWidgets.QLineEdit. selectionEnd ( )
返回类型

int

返回行编辑选定之后的直接字符索引,或-1 若未选中文本。

PySide2.QtWidgets.QLineEdit. selectionLength ( )
返回类型

int

返回选定长度。

PySide2.QtWidgets.QLineEdit. selectionStart ( )
返回类型

int

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

PySide2.QtWidgets.QLineEdit. setAlignment ( flag )
参数

flag Alignment

另请参阅

alignment()

PySide2.QtWidgets.QLineEdit. setClearButtonEnabled ( enable )
参数

enable bool

PySide2.QtWidgets.QLineEdit. setCompleter ( completer )
参数

completer QCompleter

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

要使用 QCompleter 采用 QValidator or inputMask ,需要确保模型被提供给 QCompleter 包含有效条目。可以使用 QSortFilterProxyModel 以确保 QCompleter ‘s model contains only valid entries.

c == 0, removes the current completer, effectively disabling auto completion.

PySide2.QtWidgets.QLineEdit. setCursorMoveStyle ( style )
参数

style CursorMoveStyle

另请参阅

cursorMoveStyle()

PySide2.QtWidgets.QLineEdit. setCursorPosition ( arg__1 )
参数

arg__1 int

另请参阅

cursorPosition()

PySide2.QtWidgets.QLineEdit. setDragEnabled ( b )
参数

b bool

另请参阅

dragEnabled()

PySide2.QtWidgets.QLineEdit. setEchoMode ( arg__1 )
参数

arg__1 EchoMode

另请参阅

echoMode()

PySide2.QtWidgets.QLineEdit. setFrame ( arg__1 )
参数

arg__1 bool

另请参阅

hasFrame()

PySide2.QtWidgets.QLineEdit. setInputMask ( inputMask )
参数

inputMask – unicode

另请参阅

inputMask()

PySide2.QtWidgets.QLineEdit. setMaxLength ( arg__1 )
参数

arg__1 int

另请参阅

maxLength()

PySide2.QtWidgets.QLineEdit. setModified ( arg__1 )
参数

arg__1 bool

另请参阅

isModified()

PySide2.QtWidgets.QLineEdit. setPlaceholderText ( arg__1 )
参数

arg__1 – unicode

另请参阅

placeholderText()

PySide2.QtWidgets.QLineEdit. setReadOnly ( arg__1 )
参数

arg__1 bool

另请参阅

isReadOnly()

PySide2.QtWidgets.QLineEdit. setSelection ( arg__1 , arg__2 )
参数
  • arg__1 int

  • arg__2 int

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

PySide2.QtWidgets.QLineEdit. setText ( arg__1 )
参数

arg__1 – unicode

另请参阅

text()

PySide2.QtWidgets.QLineEdit. setTextMargins ( margins )
参数

margins QMargins

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

另请参阅 textMargins() .

PySide2.QtWidgets.QLineEdit. setTextMargins ( left , top , right , bottom )
参数
  • left int

  • top int

  • right int

  • bottom int

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

另请参阅 textMargins() .

另请参阅

textMargins()

PySide2.QtWidgets.QLineEdit. setValidator ( arg__1 )
参数

arg__1 QValidator

把行编辑值的验证器设为 v .

The line edit’s returnPressed() and editingFinished() signals will only be emitted if v validates the line edit’s content as Acceptable 。用户可以将内容更改为任何 中间体 值在编辑期间,但将阻止将文本编辑为值 v 验证按 Invalid .

这允许约束当编辑完成时最终要键入的文本,同时使用户有足够自由从一种有效状态到另一种有效状态编辑文本。

v == 0, removes the current input validator. The initial setting is to have no input validator (i.e. any input is accepted up to maxLength() ).

PySide2.QtWidgets.QLineEdit. text ( )
返回类型

unicode

另请参阅

setText()

PySide2.QtWidgets.QLineEdit. textChanged ( arg__1 )
参数

arg__1 – unicode

PySide2.QtWidgets.QLineEdit. textEdited ( arg__1 )
参数

arg__1 – unicode

PySide2.QtWidgets.QLineEdit. textMargins ( )
返回类型

QMargins

Returns the widget’s text margins.

另请参阅

setTextMargins()

PySide2.QtWidgets.QLineEdit. undo ( )

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

PySide2.QtWidgets.QLineEdit. validator ( )
返回类型

QValidator

返回指向当前输入验证器的指针,或 None 若没有设置验证器。

另请参阅

setValidator()