PySide.QtGui.QLineEdit widget is a one-line text editor.
A line edit allows the user to enter and edit a single line of plain text with a useful collection of editing functions, including undo and redo, cut and paste, and drag and drop.
通过改变 PySide.QtGui.QLineEdit.echoMode() of a line edit, it can also be used as a “write-only” field, for inputs such as passwords.
可以把文本长度约束到 PySide.QtGui.QLineEdit.maxLength() . The text can be arbitrarily constrained using a PySide.QtGui.QLineEdit.validator() or an PySide.QtGui.QLineEdit.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.
相关类 PySide.QtGui.QTextEdit 允许多行,编辑富文本。
可以改变文本采用 PySide.QtGui.QLineEdit.setText() or PySide.QtGui.QLineEdit.insert() . The text is retrieved with PySide.QtGui.QLineEdit.text() ; the displayed text (which may be different, see QLineEdit.EchoMode ) 的检索采用 PySide.QtGui.QLineEdit.displayText() . Text can be selected with PySide.QtGui.QLineEdit.setSelection() or PySide.QtGui.QLineEdit.selectAll() , and the selection can be PySide.QtGui.QLineEdit.cut() , PySide.QtGui.QLineEdit.copy() ied and PySide.QtGui.QLineEdit.paste() d. The text can be aligned with PySide.QtGui.QLineEdit.setAlignment() .
当文本改变时 PySide.QtGui.QLineEdit.textChanged() signal is emitted; when the text changes other than by calling PySide.QtGui.QLineEdit.setText() the PySide.QtGui.QLineEdit.textEdited() signal is emitted; when the cursor is moved the PySide.QtGui.QLineEdit.cursorPositionChanged() signal is emitted; and when the Return or Enter key is pressed the PySide.QtGui.QLineEdit.returnPressed() 信号被发射。
当编辑完成时,由于行编辑失去聚焦或按下 Return/Enter 键 PySide.QtGui.QLineEdit.editingFinished() 信号被发射。
注意:若行编辑有设置验证器, PySide.QtGui.QLineEdit.returnPressed() / PySide.QtGui.QLineEdit.editingFinished() signals will only be emitted if the validator returns QValidator.Acceptable .
By default, QLineEdits have a frame as specified by the Windows and Motif style guides; you can turn it off by calling setFrame(false).
默认键绑定如下所述。行编辑还提供上下文菜单 (通常通过鼠标右键援引),呈现这些编辑选项中的一些。
| 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 | 重做上一撤消操作。 |
表示有效字符的任何其它键序列,将导致该字符被插入行编辑。
|
A line edit shown in the Macintosh widget style . |
|
A line edit shown in the Windows XP widget style . |
|
A line edit shown in the Plastique widget style . |
另请参阅
PySide.QtGui.QTextEdit PySide.QtGui.QLabel PySide.QtGui.QComboBox GUI 设计手册:字段、条目 行编辑范例
| 参数: |
|
|---|
构造行编辑不采用文本。
最大文本长度被设为 32767 个字符。
parent 自变量被发送给 PySide.QtGui.QWidget 构造函数。
构造行编辑包含文本 contents .
光标位置被设为行尾,且最大文本长度被设为 32767 个字符。
parent 和自变量被发送给 PySide.QtGui.QWidget 构造函数。
此枚举类型描述行编辑应如何显示其内容。
| 常量 | 描述 |
|---|---|
| QLineEdit.Normal | 显示字符如键入它们时。这是默认值。 |
| QLineEdit.NoEcho | 不显示任何东西。这可能适用于口令 (即使口令长度也应保密)。 |
| QLineEdit.Password | Display asterisks instead of the characters actually entered. |
| QLineEdit.PasswordEchoOnEdit | Display characters as they are entered while editing otherwise display asterisks. |
| 返回类型: | PySide.QtCore.Qt.Alignment |
|---|
此特性保持行编辑的对齐方式。
在这里允许水平和垂直对齐, Qt.AlignJustify 将映射到 Qt.AlignLeft .
默认情况下,此特性包含组合的 Qt.AlignLeft and Qt.AlignVCenter .
另请参阅
Qt.Alignment
若未选择文本,删除文本光标左侧字符并左移光标一位置。若有选择任何文本,光标将移动到选定文本的开头并删除所选文本。
另请参阅
del()
清零行编辑的内容。
| 返回类型: | PySide.QtGui.QCompleter |
|---|
返回当前 PySide.QtGui.QCompleter ,其提供补全。
把选中文本拷贝到剪贴板 (若有的话),且若 PySide.QtGui.QLineEdit.echoMode() is Normal .
| 返回类型: | PySide.QtGui.QMenu |
|---|
此函数创建要展示的标准上下文菜单,当用户采用鼠标右键点击行编辑时。它被调用从默认 PySide.QtGui.QLineEdit.contextMenuEvent() 处理程序。弹出菜单的所有权被转移给调用者。
| 参数: |
|
|---|
后移光标 steps 字符。若 mark 为 true,每个移过字符会被添加到选定;若 mark 为 False,清零选定。
| 参数: |
|
|---|
前移光标 steps 字符。若 mark 为 true,每个移过字符会被添加到选定;若 mark 为 False,清零选定。
| 返回类型: | PySide.QtCore.Qt.CursorMoveStyle |
|---|
此特性保持在此行编辑中光标的移动样式。
当此特性被设为 Qt.VisualMoveStyle ,行编辑将使用视觉移动样式。按左箭头键将始终导致光标向左移动,不管文本的书写方向。同样的行为适用于右箭头键。
当特性为 Qt.LogicalMoveStyle (默认),在 LTR 文本块中,当按左箭头键时增加光标位置,当按右箭头键时减少光标位置。若文本块是 (RTL) 从右到左,适用相反行为。
| 返回类型: | PySide.QtCore.int |
|---|
此特性保持此行编辑的当前光标位置。
设置光标位置导致重绘,当适当时。
默认情况下,此特性包含 0 值。
| 参数: | pos – PySide.QtCore.QPoint |
|---|---|
| 返回类型: | PySide.QtCore.int |
返回光标位置在点 pos .
| 参数: |
|
|---|
| 返回类型: | PySide.QtCore.QRect |
|---|
返回包括行编辑光标的矩形。
| 参数: | mark – PySide.QtCore.bool |
|---|
将光标后移一单词。若 mark 为 true,单词还被选中。
| 参数: | mark – PySide.QtCore.bool |
|---|
将光标前移一单词。若 mark 为 true,单词还被选中。
把选中文本拷贝到剪贴板且删除它 (若有的话),且若 PySide.QtGui.QLineEdit.echoMode() is Normal .
If the current validator disallows deleting the selected text, PySide.QtGui.QLineEdit.cut() will copy without deleting.
若未选择文本,删除文本光标右侧字符。若有选择任何文本,光标将移动到选定文本的开头并删除所选文本。
取消任何选中文本的选择。
| 返回类型: | unicode |
|---|
此特性保持显示文本。
若 PySide.QtGui.QLineEdit.echoMode() is Normal 这将返回相同的如 PySide.QtGui.QLineEdit.text() ; if QLineEdit.EchoMode is Password or PasswordEchoOnEdit it returns a string of asterisks PySide.QtGui.QLineEdit.text() . length() characters long, e.g. “******”; if QLineEdit.EchoMode is NoEcho returns an empty string, “”.
默认情况下,此特性包含空字符串。
另请参阅
PySide.QtGui.QLineEdit.setEchoMode() PySide.QtGui.QLineEdit.text() QLineEdit.EchoMode
| 返回类型: | PySide.QtCore.bool |
|---|
此特性保存 QLineEdit 是否开始拖曳,若用户在某些选定文本上按下并移动鼠标。
拖曳是禁用的,默认情况下。
| 返回类型: | PySide.QtGui.QLineEdit.EchoMode |
|---|
此特性保持行编辑的回显模式。
回显模式确定在行编辑中键入的文本,如何显示 (或回显) 给用户。
最常见设置是 Normal ,用户键入的文本逐字显示,但 PySide.QtGui.QLineEdit 还支持允许抑制或遮盖键入文本的模式:这些包括 NoEcho , Password and PasswordEchoOnEdit .
Widget 的显示及拷贝或拖曳文本的能力,受此设置影响。
默认情况下,此特性被设为 Normal .
另请参阅
QLineEdit.EchoMode PySide.QtGui.QLineEdit.displayText()
| 参数: | mark – PySide.QtCore.bool |
|---|
将光标移至行末尾,除非光标已移到那里。若 mark 为 true,选择文本到最后位置;否则,取消选择任何文本的选定若光标被移动。
Returns the widget's text margins for left , top , right ,和 bottom .
| 返回类型: | PySide.QtCore.bool |
|---|
此特性保持输入是否满足 PySide.QtGui.QLineEdit.inputMask() and the validator..
默认情况下,此特性为 true。
| 返回类型: | PySide.QtCore.bool |
|---|
此特性保持行编辑是否采用框架绘制自身。
若使行编辑能够 (默认) 在框架内绘制自身,否则,行编辑将绘制自身不用任何框架。
| 返回类型: | PySide.QtCore.bool |
|---|
此特性保持是否有选中任何文本。
PySide.QtGui.QLineEdit.hasSelectedText() returns true if some or all of the text has been selected by the user; otherwise returns false.
默认情况下,此特性为 false。
| 参数: | mark – PySide.QtCore.bool |
|---|
将光标移至行开头,除非光标已移到那里。若 mark 为 true,选择文本到第一位置;否则,取消选择任何文本的选定若光标被移动。
| 参数: | option – PySide.QtGui.QStyleOptionFrame |
|---|
初始化 option 采用值来自此 PySide.QtGui.QLineEdit 。此方法对子类是有用的,当需要 PySide.QtGui.QStyleOptionFrame or PySide.QtGui.QStyleOptionFrameV2 , but don't want to fill in all the information themselves. This function will check the version of the PySide.QtGui.QStyleOptionFrame and fill in the additional values for a PySide.QtGui.QStyleOptionFrameV2 .
| 返回类型: | unicode |
|---|
This property holds The validation input mask.
If no mask is set, PySide.QtGui.QLineEdit.inputMask() returns an empty string.
设置 PySide.QtGui.QLineEdit ‘s validation mask. Validators can be used instead of, or in conjunction with masks; see PySide.QtGui.QLineEdit.setValidator() .
不设置掩码并返回正常 PySide.QtGui.QLineEdit operation by passing an empty string (“”) or just calling PySide.QtGui.QLineEdit.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 .
| 字符 | 含义 |
| 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.
范例:
| Mask | 注意事项 |
| 000.000.000.000;_ | IP 地址;空白为 _ . |
| HH:HH:HH:HH:HH:HH;_ | MAC 地址 |
| 0000-00-00 | ISO 日期;空白为 space |
| >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# | 许可编号; 空白为 - 且所有 (字母) 字符被转换成大写。 |
要获得范围控制 (如:IP 地址),使用掩码同 validators .
| 参数: | arg__1 – unicode |
|---|
删除任何选中文本,插入 newText ,并验证结果。若有效,则将其设为行编辑的新内容。
| 返回类型: | PySide.QtCore.bool |
|---|
此特性保持行编辑内容是否已被用户修改。
修改标志从不被读取由 PySide.QtGui.QLineEdit ;它拥有默认值 false,且被改为 true 每当用户改变行编辑内容时。
This is useful for things that need to provide a default value but do not start out knowing what the default should be (perhaps it depends on other fields on the form). Start the line edit without the best default, and when the default is known, if modified() returns false (the user hasn't entered any text), insert the default value.
调用 PySide.QtGui.QLineEdit.setText() resets the modified flag to false.
| 返回类型: | PySide.QtCore.bool |
|---|
This property holds whether the line edit is read only..
在只读模式下,用户仍可以将文本拷贝到剪贴板,或拖放文本 (若 PySide.QtGui.QLineEdit.echoMode() is Normal ),但无法编辑它。
PySide.QtGui.QLineEdit 在只读模式下不展示光标。
默认情况下,此特性为 false。
| 返回类型: | PySide.QtCore.bool |
|---|
此特性保持重做是否可用。
重做变为可用,一旦用户对行编辑中的文本有履行一次或多次撤消操作。
默认情况下,此特性为 false。
| 返回类型: | PySide.QtCore.bool |
|---|
此特性保持撤消是否可用。
撤消变为可用,一旦用户有修改行编辑文本。
默认情况下,此特性为 false。
| 返回类型: | PySide.QtCore.int |
|---|
此特性保持文本的最大准许长度。
若文本太长,则在限制处截取它。
若发生截断,将取消选择任何文本的选定,光标位置设为 0 并展示字符串的第一部分。
若行编辑拥有输入掩码,掩码将定义最大字符串长度。
默认情况下,此特性包含 32767 值。
将剪贴板文本插入在光标位置处,删除任何选中文本,若行编辑不为 只读 .
If the end result would not be acceptable to the current validator ,什么都不发生。
| 返回类型: | unicode |
|---|
此特性保持行编辑的占位符文本。
Setting this property makes the line edit display a grayed-out placeholder text as long as the PySide.QtGui.QLineEdit.text() is empty and the widget doesn't have focus.
默认情况下,此特性包含空字符串。
重做上一操作,若重做 available .
选择所有文本 (即:突显文本) 并将光标移至末尾。这很有用当插入默认值时,因为若用户在点击 Widget 之前键入,则选中文本会被删除。
| 返回类型: | unicode |
|---|
此特性保持选中文本。
若没有选中文本,此特性的值为空字符串。
默认情况下,此特性包含空字符串。
| 返回类型: | PySide.QtCore.int |
|---|
PySide.QtGui.QLineEdit.selectionStart() returns the index of the first selected character in the line edit or -1 if no text is selected.
| 参数: | flag – PySide.QtCore.Qt.Alignment |
|---|
此特性保持行编辑的对齐方式。
在这里允许水平和垂直对齐, Qt.AlignJustify 将映射到 Qt.AlignLeft .
默认情况下,此特性包含组合的 Qt.AlignLeft and Qt.AlignVCenter .
另请参阅
Qt.Alignment
| 参数: | completer – PySide.QtGui.QCompleter |
|---|
将为此行编辑提供自动补全的补全器设为 c 。补全模式的设置使用 QCompleter.setCompletionMode() .
要使用 PySide.QtGui.QCompleter 采用 PySide.QtGui.QValidator or QLineEdit.inputMask ,需要确保模型被提供给 PySide.QtGui.QCompleter 包含有效条目。可以使用 PySide.QtGui.QSortFilterProxyModel 以确保 PySide.QtGui.QCompleter ‘s model contains only valid entries.
若 c == 0, PySide.QtGui.QLineEdit.setCompleter() removes the current completer, effectively disabling auto completion.
| 参数: | style – PySide.QtCore.Qt.CursorMoveStyle |
|---|
此特性保持在此行编辑中光标的移动样式。
当此特性被设为 Qt.VisualMoveStyle ,行编辑将使用视觉移动样式。按左箭头键将始终导致光标向左移动,不管文本的书写方向。同样的行为适用于右箭头键。
当特性为 Qt.LogicalMoveStyle (默认),在 LTR 文本块中,当按左箭头键时增加光标位置,当按右箭头键时减少光标位置。若文本块是 (RTL) 从右到左,适用相反行为。
| 参数: | arg__1 – PySide.QtCore.int |
|---|
此特性保持此行编辑的当前光标位置。
设置光标位置导致重绘,当适当时。
默认情况下,此特性包含 0 值。
| 参数: | b – PySide.QtCore.bool |
|---|
此特性保存 QLineEdit 是否开始拖曳,若用户在某些选定文本上按下并移动鼠标。
拖曳是禁用的,默认情况下。
| 参数: | arg__1 – PySide.QtGui.QLineEdit.EchoMode |
|---|
此特性保持行编辑的回显模式。
回显模式确定在行编辑中键入的文本,如何显示 (或回显) 给用户。
最常见设置是 Normal ,用户键入的文本逐字显示,但 PySide.QtGui.QLineEdit 还支持允许抑制或遮盖键入文本的模式:这些包括 NoEcho , Password and PasswordEchoOnEdit .
Widget 的显示及拷贝或拖曳文本的能力,受此设置影响。
默认情况下,此特性被设为 Normal .
另请参阅
QLineEdit.EchoMode PySide.QtGui.QLineEdit.displayText()
| 参数: | arg__1 – PySide.QtCore.bool |
|---|
此特性保持行编辑是否采用框架绘制自身。
若使行编辑能够 (默认) 在框架内绘制自身,否则,行编辑将绘制自身不用任何框架。
| 参数: | inputMask – unicode |
|---|
This property holds The validation input mask.
If no mask is set, PySide.QtGui.QLineEdit.inputMask() returns an empty string.
设置 PySide.QtGui.QLineEdit ‘s validation mask. Validators can be used instead of, or in conjunction with masks; see PySide.QtGui.QLineEdit.setValidator() .
不设置掩码并返回正常 PySide.QtGui.QLineEdit operation by passing an empty string (“”) or just calling PySide.QtGui.QLineEdit.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 .
| 字符 | 含义 |
| 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.
范例:
| Mask | 注意事项 |
| 000.000.000.000;_ | IP 地址;空白为 _ . |
| HH:HH:HH:HH:HH:HH;_ | MAC 地址 |
| 0000-00-00 | ISO 日期;空白为 space |
| >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# | 许可编号; 空白为 - 且所有 (字母) 字符被转换成大写。 |
要获得范围控制 (如:IP 地址),使用掩码同 validators .
| 参数: | arg__1 – PySide.QtCore.int |
|---|
此特性保持文本的最大准许长度。
若文本太长,则在限制处截取它。
若发生截断,将取消选择任何文本的选定,光标位置设为 0 并展示字符串的第一部分。
若行编辑拥有输入掩码,掩码将定义最大字符串长度。
默认情况下,此特性包含 32767 值。
| 参数: | arg__1 – PySide.QtCore.bool |
|---|
此特性保持行编辑内容是否已被用户修改。
修改标志从不被读取由 PySide.QtGui.QLineEdit ;它拥有默认值 false,且被改为 true 每当用户改变行编辑内容时。
This is useful for things that need to provide a default value but do not start out knowing what the default should be (perhaps it depends on other fields on the form). Start the line edit without the best default, and when the default is known, if modified() returns false (the user hasn't entered any text), insert the default value.
调用 PySide.QtGui.QLineEdit.setText() resets the modified flag to false.
| 参数: | arg__1 – unicode |
|---|
此特性保持行编辑的占位符文本。
Setting this property makes the line edit display a grayed-out placeholder text as long as the PySide.QtGui.QLineEdit.text() is empty and the widget doesn't have focus.
默认情况下,此特性包含空字符串。
| 参数: | arg__1 – PySide.QtCore.bool |
|---|
This property holds whether the line edit is read only..
在只读模式下,用户仍可以将文本拷贝到剪贴板,或拖放文本 (若 PySide.QtGui.QLineEdit.echoMode() is Normal ),但无法编辑它。
PySide.QtGui.QLineEdit 在只读模式下不展示光标。
默认情况下,此特性为 false。
| 参数: |
|
|---|
选择文本从位置 start 和对于 length 个字符。负长度是允许的。
| 参数: | arg__1 – unicode |
|---|
此特性保持行编辑的文本。
设置此特性清零选定,清零撤消/重做历史,把光标移至行尾并重置 modified() property to false. The text is not validated when inserted with PySide.QtGui.QLineEdit.setText() .
文本被截取到 PySide.QtGui.QLineEdit.maxLength() length.
默认情况下,此特性包含空字符串。
| 参数: |
|
|---|
将框架围绕文本的边距尺寸设为 left , top , right ,和 bottom .
| 参数: | margins – PySide.QtCore.QMargins |
|---|
设置 margins 围绕文本在框架内。
| 参数: | arg__1 – PySide.QtGui.QValidator |
|---|
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, PySide.QtGui.QLineEdit.setValidator() removes the current input validator. The initial setting is to have no input validator (i.e. any input is accepted up to PySide.QtGui.QLineEdit.maxLength() ).
| 返回类型: | unicode |
|---|
此特性保持行编辑的文本。
设置此特性清零选定,清零撤消/重做历史,把光标移至行尾并重置 modified() property to false. The text is not validated when inserted with PySide.QtGui.QLineEdit.setText() .
文本被截取到 PySide.QtGui.QLineEdit.maxLength() length.
默认情况下,此特性包含空字符串。
| 参数: | arg__1 – unicode |
|---|
| 参数: | arg__1 – unicode |
|---|
| 返回类型: | PySide.QtCore.QMargins |
|---|
返回 Widget 的文本边距。
撤消上一操作,若撤消 available 。取消当前任何选定,并将选择起始更新成当前光标位置。
| 返回类型: | PySide.QtGui.QValidator |
|---|
Returns a pointer to the current input validator, or 0 if no validator has been set.