The 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.
By changing the PySide.QtGui.QLineEdit.echoMode() of a line edit, it can also be used as a “write-only” field, for inputs such as passwords.
The length of the text can be constrained to 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.
A related class is PySide.QtGui.QTextEdit which allows multi-line, rich text editing.
You can change the text with 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 ) is retrieved with 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() .
When the text changes the 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() signal is emitted.
When editing is finished, either because the line edit lost focus or Return/Enter is pressed the PySide.QtGui.QLineEdit.editingFinished() signal is emitted.
Note that if there is a validator set on the line edit, the 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).
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.
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. Any other key sequence that represents a valid character, will cause the character to be inserted into the line edit.
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 . See also
PySide.QtGui.QTextEdit PySide.QtGui.QLabel PySide.QtGui.QComboBox GUI Design Handbook: Field, Entry Line Edits Example
Parameters: |
|
---|
Constructs a line edit with no text.
The maximum text length is set to 32767 characters.
The parent argument is sent to the PySide.QtGui.QWidget constructor.
Constructs a line edit containing the text contents .
The cursor position is set to the end of the line and the maximum text length to 32767 characters.
The parent and argument is sent to the PySide.QtGui.QWidget constructor.
This enum type describes how a line edit should display its contents.
Constant | Description |
---|---|
QLineEdit.Normal | Display characters as they are entered. This is the default. |
QLineEdit.NoEcho | Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret. |
QLineEdit.Password | Display asterisks instead of the characters actually entered. |
QLineEdit.PasswordEchoOnEdit | Display characters as they are entered while editing otherwise display asterisks. |
Return type: | PySide.QtCore.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 .
See also
Qt.Alignment
If no text is selected, deletes the character to the left of the text cursor and moves the cursor one position to the left. If any text is selected, the cursor is moved to the beginning of the selected text and the selected text is deleted.
See also
del()
Clears the contents of the line edit.
Return type: | PySide.QtGui.QCompleter |
---|
Returns the current PySide.QtGui.QCompleter that provides completions.
Copies the selected text to the clipboard, if there is any, and if PySide.QtGui.QLineEdit.echoMode() is Normal .
Return type: | PySide.QtGui.QMenu |
---|
This function creates the standard context menu which is shown when the user clicks on the line edit with the right mouse button. It is called from the default PySide.QtGui.QLineEdit.contextMenuEvent() handler. The popup menu’s ownership is transferred to the caller.
Parameters: |
|
---|
Moves the cursor back steps characters. If mark is true each character moved over is added to the selection; if mark is false the selection is cleared.
Parameters: |
|
---|
Moves the cursor forward steps characters. If mark is true each character moved over is added to the selection; if mark is false the selection is cleared.
Return type: | PySide.QtCore.Qt.CursorMoveStyle |
---|
This property holds the movement style of cursor in this line edit.
When this property is set to Qt.VisualMoveStyle , the line edit will use visual movement style. Pressing the left arrow key will always cause the cursor to move left, regardless of the text’s writing direction. The same behavior applies to right arrow key.
When the property is Qt.LogicalMoveStyle (the default), within a LTR text block, increase cursor position when pressing left arrow key, decrease cursor position when pressing the right arrow key. If the text block is right to left, the opposite behavior applies.
Return type: | PySide.QtCore.int |
---|
This property holds the current cursor position for this line edit.
Setting the cursor position causes a repaint when appropriate.
By default, this property contains a value of 0.
Parameters: | pos – PySide.QtCore.QPoint |
---|---|
Return type: | PySide.QtCore.int |
Returns the cursor position under the point pos .
Parameters: |
|
---|
Return type: | PySide.QtCore.QRect |
---|
Returns a rectangle that includes the lineedit cursor.
Parameters: | mark – PySide.QtCore.bool |
---|
Moves the cursor one word backward. If mark is true, the word is also selected.
Parameters: | mark – PySide.QtCore.bool |
---|
Moves the cursor one word forward. If mark is true, the word is also selected.
Copies the selected text to the clipboard and deletes it, if there is any, and if PySide.QtGui.QLineEdit.echoMode() is Normal .
If the current validator disallows deleting the selected text, PySide.QtGui.QLineEdit.cut() will copy without deleting.
If no text is selected, deletes the character to the right of the text cursor. If any text is selected, the cursor is moved to the beginning of the selected text and the selected text is deleted.
See also
Deselects any selected text.
Return type: | unicode |
---|
This property holds the displayed text.
If PySide.QtGui.QLineEdit.echoMode() is Normal this returns the same as 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, “”.
By default, this property contains an empty string.
See also
PySide.QtGui.QLineEdit.setEchoMode() PySide.QtGui.QLineEdit.text() QLineEdit.EchoMode
Return type: | PySide.QtCore.bool |
---|
This property holds whether the lineedit starts a drag if the user presses and moves the mouse on some selected text.
Dragging is disabled by default.
Return type: | PySide.QtGui.QLineEdit.EchoMode |
---|
This property holds the line edit’s echo mode.
The echo mode determines how the text entered in the line edit is displayed (or echoed) to the user.
The most common setting is Normal , in which the text entered by the user is displayed verbatim, but PySide.QtGui.QLineEdit also supports modes that allow the entered text to be suppressed or obscured: these include NoEcho , Password and PasswordEchoOnEdit .
The widget’s display and the ability to copy or drag the text is affected by this setting.
By default, this property is set to Normal .
See also
QLineEdit.EchoMode PySide.QtGui.QLineEdit.displayText()
Parameters: | mark – PySide.QtCore.bool |
---|
Moves the text cursor to the end of the line unless it is already there. If mark is true, text is selected towards the last position; otherwise, any selected text is unselected if the cursor is moved.
See also
Returns the widget’s text margins for left , top , right , and bottom .
Return type: | PySide.QtCore.bool |
---|
This property holds whether the input satisfies the PySide.QtGui.QLineEdit.inputMask() and the validator..
By default, this property is true.
Return type: | PySide.QtCore.bool |
---|
This property holds whether the line edit draws itself with a frame.
If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame.
Return type: | PySide.QtCore.bool |
---|
This property holds whether there is any text selected.
PySide.QtGui.QLineEdit.hasSelectedText() returns true if some or all of the text has been selected by the user; otherwise returns false.
By default, this property is false.
Parameters: | mark – PySide.QtCore.bool |
---|
Moves the text cursor to the beginning of the line unless it is already there. If mark is true, text is selected towards the first position; otherwise, any selected text is unselected if the cursor is moved.
See also
Parameters: | option – PySide.QtGui.QStyleOptionFrame |
---|
Initialize option with the values from this PySide.QtGui.QLineEdit . This method is useful for subclasses when they need a 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 .
See also
Return type: | unicode |
---|
This property holds The validation input mask.
If no mask is set, PySide.QtGui.QLineEdit.inputMask() returns an empty string.
Sets the PySide.QtGui.QLineEdit ‘s validation mask. Validators can be used instead of, or in conjunction with masks; see PySide.QtGui.QLineEdit.setValidator() .
Unset the mask and return to normal 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 .
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 .
See also
Parameters: | arg__1 – unicode |
---|
Deletes any selected text, inserts newText , and validates the result. If it is valid, it sets it as the new contents of the line edit.
Return type: | PySide.QtCore.bool |
---|
This property holds whether the line edit’s contents has been modified by the user.
The modified flag is never read by PySide.QtGui.QLineEdit ; it has a default value of false and is changed to true whenever the user changes the line edit’s contents.
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.
Calling PySide.QtGui.QLineEdit.setText() resets the modified flag to false.
Return type: | PySide.QtCore.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 PySide.QtGui.QLineEdit.echoMode() is Normal ), but cannot edit it.
PySide.QtGui.QLineEdit does not show a cursor in read-only mode.
By default, this property is false.
See also
Return type: | PySide.QtCore.bool |
---|
This property holds whether redo is available.
Redo becomes available once the user has performed one or more undo operations on text in the line edit.
By default, this property is false.
Return type: | PySide.QtCore.bool |
---|
This property holds whether undo is available.
Undo becomes available once the user has modified the text in the line edit.
By default, this property is false.
Return type: | PySide.QtCore.int |
---|
This property holds the maximum permitted length of the text.
If the text is too long, it is truncated at the limit.
If truncation occurs any selected text will be unselected, the cursor position is set to 0 and the first part of the string is shown.
If the line edit has an input mask, the mask defines the maximum string length.
By default, this property contains a value of 32767.
See also
Inserts the clipboard’s text at the cursor position, deleting any selected text, providing the line edit is not read-only .
If the end result would not be acceptable to the current validator , nothing happens.
Return type: | unicode |
---|
This property holds the line edit’s placeholder text.
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.
By default, this property contains an empty string.
See also
Redoes the last operation if redo is available .
Selects all the text (i.e. highlights it) and moves the cursor to the end. This is useful when a default value has been inserted because if the user types before clicking on the widget, the selected text will be deleted.
Return type: | unicode |
---|
This property holds the selected text.
If there is no selected text this property’s value is an empty string.
By default, this property contains an empty string.
Return type: | 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.
Parameters: | flag – PySide.QtCore.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 .
See also
Qt.Alignment
Parameters: | completer – PySide.QtGui.QCompleter |
---|
Sets this line edit to provide auto completions from the completer, c . The completion mode is set using QCompleter.setCompletionMode() .
To use a PySide.QtGui.QCompleter with a PySide.QtGui.QValidator or QLineEdit.inputMask , you need to ensure that the model provided to PySide.QtGui.QCompleter contains valid entries. You can use the PySide.QtGui.QSortFilterProxyModel to ensure that the PySide.QtGui.QCompleter ‘s model contains only valid entries.
If c == 0, PySide.QtGui.QLineEdit.setCompleter() removes the current completer, effectively disabling auto completion.
Parameters: | style – PySide.QtCore.Qt.CursorMoveStyle |
---|
This property holds the movement style of cursor in this line edit.
When this property is set to Qt.VisualMoveStyle , the line edit will use visual movement style. Pressing the left arrow key will always cause the cursor to move left, regardless of the text’s writing direction. The same behavior applies to right arrow key.
When the property is Qt.LogicalMoveStyle (the default), within a LTR text block, increase cursor position when pressing left arrow key, decrease cursor position when pressing the right arrow key. If the text block is right to left, the opposite behavior applies.
Parameters: | arg__1 – PySide.QtCore.int |
---|
This property holds the current cursor position for this line edit.
Setting the cursor position causes a repaint when appropriate.
By default, this property contains a value of 0.
Parameters: | b – PySide.QtCore.bool |
---|
This property holds whether the lineedit starts a drag if the user presses and moves the mouse on some selected text.
Dragging is disabled by default.
Parameters: | arg__1 – PySide.QtGui.QLineEdit.EchoMode |
---|
This property holds the line edit’s echo mode.
The echo mode determines how the text entered in the line edit is displayed (or echoed) to the user.
The most common setting is Normal , in which the text entered by the user is displayed verbatim, but PySide.QtGui.QLineEdit also supports modes that allow the entered text to be suppressed or obscured: these include NoEcho , Password and PasswordEchoOnEdit .
The widget’s display and the ability to copy or drag the text is affected by this setting.
By default, this property is set to Normal .
See also
QLineEdit.EchoMode PySide.QtGui.QLineEdit.displayText()
Parameters: | arg__1 – PySide.QtCore.bool |
---|
This property holds whether the line edit draws itself with a frame.
If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame.
Parameters: | inputMask – unicode |
---|
This property holds The validation input mask.
If no mask is set, PySide.QtGui.QLineEdit.inputMask() returns an empty string.
Sets the PySide.QtGui.QLineEdit ‘s validation mask. Validators can be used instead of, or in conjunction with masks; see PySide.QtGui.QLineEdit.setValidator() .
Unset the mask and return to normal 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 .
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 .
See also
Parameters: | arg__1 – PySide.QtCore.int |
---|
This property holds the maximum permitted length of the text.
If the text is too long, it is truncated at the limit.
If truncation occurs any selected text will be unselected, the cursor position is set to 0 and the first part of the string is shown.
If the line edit has an input mask, the mask defines the maximum string length.
By default, this property contains a value of 32767.
See also
Parameters: | arg__1 – PySide.QtCore.bool |
---|
This property holds whether the line edit’s contents has been modified by the user.
The modified flag is never read by PySide.QtGui.QLineEdit ; it has a default value of false and is changed to true whenever the user changes the line edit’s contents.
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.
Calling PySide.QtGui.QLineEdit.setText() resets the modified flag to false.
Parameters: | arg__1 – unicode |
---|
This property holds the line edit’s placeholder text.
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.
By default, this property contains an empty string.
See also
Parameters: | arg__1 – PySide.QtCore.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 PySide.QtGui.QLineEdit.echoMode() is Normal ), but cannot edit it.
PySide.QtGui.QLineEdit does not show a cursor in read-only mode.
By default, this property is false.
See also
Parameters: |
|
---|
Selects text from position start and for length characters. Negative lengths are allowed.
Parameters: | arg__1 – unicode |
---|
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 PySide.QtGui.QLineEdit.setText() .
The text is truncated to PySide.QtGui.QLineEdit.maxLength() length.
By default, this property contains an empty string.
Parameters: |
|
---|
Sets the margins around the text inside the frame to have the sizes left , top , right , and bottom .
See also PySide.QtGui.QLineEdit.getTextMargins() .
See also
Parameters: | margins – PySide.QtCore.QMargins |
---|
Sets the margins around the text inside the frame.
See also PySide.QtGui.QLineEdit.textMargins() .
Parameters: | 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.
If 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() ).
Return type: | unicode |
---|
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 PySide.QtGui.QLineEdit.setText() .
The text is truncated to PySide.QtGui.QLineEdit.maxLength() length.
By default, this property contains an empty string.
Parameters: | arg__1 – unicode |
---|
Parameters: | arg__1 – unicode |
---|
Return type: | PySide.QtCore.QMargins |
---|
Returns the widget’s text margins.
Undoes the last operation if undo is available . Deselects any current selection, and updates the selection start to the current cursor position.
Return type: | PySide.QtGui.QValidator |
---|
Returns a pointer to the current input validator, or 0 if no validator has been set.