QLineEdit¶
The QLineEdit
widget is a one-line text editor. More…

Synopsis¶
Functions¶
def
addAction
(action, position)def
addAction
(icon, position)def
alignment
()def
backspace
()def
clear
()def
completer
()def
copy
()def
createStandardContextMenu
()def
cursorBackward
(mark[, steps=1])def
cursorForward
(mark[, steps=1])def
cursorMoveStyle
()def
cursorPosition
()def
cursorPositionAt
(pos)def
cursorPositionChanged
(arg__1, arg__2)def
cursorRect
()def
cursorWordBackward
(mark)def
cursorWordForward
(mark)def
cut
()def
del_
()def
deselect
()def
displayText
()def
dragEnabled
()def
echoMode
()def
editingFinished
()def
end
(mark)def
hasAcceptableInput
()def
hasFrame
()def
hasSelectedText
()def
home
(mark)def
inputMask
()def
inputMethodQuery
(property, argument)def
inputRejected
()def
insert
(arg__1)def
isClearButtonEnabled
()def
isModified
()def
isReadOnly
()def
isRedoAvailable
()def
isUndoAvailable
()def
maxLength
()def
paste
()def
placeholderText
()def
redo
()def
returnPressed
()def
selectAll
()def
selectedText
()def
selectionChanged
()def
selectionEnd
()def
selectionLength
()def
selectionStart
()def
setAlignment
(flag)def
setClearButtonEnabled
(enable)def
setCompleter
(completer)def
setCursorMoveStyle
(style)def
setCursorPosition
(arg__1)def
setDragEnabled
(b)def
setEchoMode
(arg__1)def
setFrame
(arg__1)def
setInputMask
(inputMask)def
setMaxLength
(arg__1)def
setModified
(arg__1)def
setPlaceholderText
(arg__1)def
setReadOnly
(arg__1)def
setSelection
(arg__1, arg__2)def
setText
(arg__1)def
setTextMargins
(left, top, right, bottom)def
setTextMargins
(margins)def
setValidator
(arg__1)def
text
()def
textChanged
(arg__1)def
textEdited
(arg__1)def
textMargins
()def
undo
()def
validator
()
Virtual functions¶
def
initStyleOption
(option)
Detailed Description¶
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 (see setDragEnabled()
).
By changing the 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 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.
A related class is QTextEdit
which allows multi-line, rich text editing.
You can change the text with setText()
or insert()
. The text is retrieved with text()
; the displayed text (which may be different, see EchoMode
) is retrieved with 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()
.
When the text changes the textChanged()
signal is emitted; when the text changes other than by calling setText()
the signal is emitted; when the cursor is moved the signal is emitted; and when the Return or Enter key is pressed the signal is emitted.
When editing is finished, either because the line edit lost focus or Return/Enter is pressed the signal is emitted.
Note that if there is a validator set on the line edit, the / signals will only be emitted if the validator returns Acceptable
.
By default, QLineEdits have a frame as specified by platform 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. .. _desc:
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.
See also
QTextEdit
QLabel
QComboBox GUI Design Handbook: Field, Entry Line Edits Example
-
class
PySide6.QtWidgets.
QLineEdit
([parent=None])¶ PySide6.QtWidgets.QLineEdit(arg__1[, parent=None])
- Parameters
parent –
PySide6.QtWidgets.QWidget
arg__1 – str
Constructs a line edit with no text.
The maximum text length is set to 32767 characters.
The parent
argument is sent to the QWidget constructor.
See also
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 QWidget constructor.
See also
-
PySide6.QtWidgets.QLineEdit.
ActionPosition
¶
This enum type describes how a line edit should display the action widgets to be added.
Constant
Description
QLineEdit.LeadingPosition
The widget is displayed to the left of the text when using layout direction
Qt::LeftToRight
or to the right when usingQt::RightToLeft
, respectively.QLineEdit.TrailingPosition
The widget is displayed to the right of the text when using layout direction
Qt::LeftToRight
or to the left when usingQt::RightToLeft
, respectively.See also
-
PySide6.QtWidgets.QLineEdit.
EchoMode
¶
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 platform-dependent password mask characters instead of the characters actually entered.
QLineEdit.PasswordEchoOnEdit
Display characters as they are entered while editing otherwise display characters as with
Password
.See also
-
PySide6.QtWidgets.QLineEdit.
addAction
(icon, position)¶ - Parameters
icon –
PySide6.QtGui.QIcon
position –
ActionPosition
- Return type
-
PySide6.QtWidgets.QLineEdit.
addAction
(action, position) - Parameters
action –
PySide6.QtGui.QAction
position –
ActionPosition
Adds the action
to the list of actions at the position
.
-
PySide6.QtWidgets.QLineEdit.
alignment
()¶ - Return type
Alignment
See also
-
PySide6.QtWidgets.QLineEdit.
backspace
()¶
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()
-
PySide6.QtWidgets.QLineEdit.
clear
()¶
Clears the contents of the line edit.
-
PySide6.QtWidgets.QLineEdit.
completer
()¶ - Return type
Returns the current QCompleter
that provides completions.
See also
-
PySide6.QtWidgets.QLineEdit.
copy
()¶
Copies the selected text to the clipboard, if there is any, and if echoMode()
is Normal
.
-
PySide6.QtWidgets.QLineEdit.
createStandardContextMenu
()¶ - Return type
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 contextMenuEvent()
handler. The popup menu’s ownership is transferred to the caller.
-
PySide6.QtWidgets.QLineEdit.
cursorBackward
(mark[, steps=1])¶ - Parameters
mark – bool
steps – int
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.
See also
-
PySide6.QtWidgets.QLineEdit.
cursorForward
(mark[, steps=1])¶ - Parameters
mark – bool
steps – int
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.
See also
-
PySide6.QtWidgets.QLineEdit.
cursorMoveStyle
()¶ - Return type
See also
-
PySide6.QtWidgets.QLineEdit.
cursorPosition
()¶ - Return type
int
See also
-
PySide6.QtWidgets.QLineEdit.
cursorPositionAt
(pos)¶ - Parameters
pos –
PySide6.QtCore.QPoint
- Return type
int
Returns the cursor position under the point pos
.
-
PySide6.QtWidgets.QLineEdit.
cursorPositionChanged
(arg__1, arg__2)¶ - Parameters
arg__1 – int
arg__2 – int
-
PySide6.QtWidgets.QLineEdit.
cursorRect
()¶ - Return type
Returns a rectangle that includes the lineedit cursor.
-
PySide6.QtWidgets.QLineEdit.
cursorWordBackward
(mark)¶ - Parameters
mark – bool
Moves the cursor one word backward. If mark
is true, the word is also selected.
See also
-
PySide6.QtWidgets.QLineEdit.
cursorWordForward
(mark)¶ - Parameters
mark – bool
Moves the cursor one word forward. If mark
is true, the word is also selected.
See also
-
PySide6.QtWidgets.QLineEdit.
cut
()¶
Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode()
is Normal
.
If the current validator disallows deleting the selected text, will copy without deleting.
See also
-
PySide6.QtWidgets.QLineEdit.
del_
()¶
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
-
PySide6.QtWidgets.QLineEdit.
deselect
()¶
Deselects any selected text.
See also
-
PySide6.QtWidgets.QLineEdit.
displayText
()¶ - Return type
str
-
PySide6.QtWidgets.QLineEdit.
dragEnabled
()¶ - Return type
bool
See also
-
PySide6.QtWidgets.QLineEdit.
echoMode
()¶ - Return type
See also
-
PySide6.QtWidgets.QLineEdit.
editingFinished
()¶
-
PySide6.QtWidgets.QLineEdit.
end
(mark)¶ - Parameters
mark – 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
-
PySide6.QtWidgets.QLineEdit.
hasAcceptableInput
()¶ - Return type
bool
-
PySide6.QtWidgets.QLineEdit.
hasFrame
()¶ - Return type
bool
-
PySide6.QtWidgets.QLineEdit.
hasSelectedText
()¶ - Return type
bool
-
PySide6.QtWidgets.QLineEdit.
home
(mark)¶ - Parameters
mark – 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
-
PySide6.QtWidgets.QLineEdit.
initStyleOption
(option)¶ - Parameters
option –
PySide6.QtWidgets.QStyleOptionFrame
Initialize option
with the values from this QLineEdit
. This method is useful for subclasses when they need a QStyleOptionFrame
, but don’t want to fill in all the information themselves.
See also
-
PySide6.QtWidgets.QLineEdit.
inputMask
()¶ - Return type
str
See also
-
PySide6.QtWidgets.QLineEdit.
inputMethodQuery
(property, argument)¶ - Parameters
property –
InputMethodQuery
argument – object
- Return type
object
-
PySide6.QtWidgets.QLineEdit.
inputRejected
()¶
-
PySide6.QtWidgets.QLineEdit.
insert
(arg__1)¶ - Parameters
arg__1 – str
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.
-
PySide6.QtWidgets.QLineEdit.
isClearButtonEnabled
()¶ - Return type
bool
-
PySide6.QtWidgets.QLineEdit.
isModified
()¶ - Return type
bool
-
PySide6.QtWidgets.QLineEdit.
isReadOnly
()¶ - Return type
bool
-
PySide6.QtWidgets.QLineEdit.
isRedoAvailable
()¶ - Return type
bool
-
PySide6.QtWidgets.QLineEdit.
isUndoAvailable
()¶ - Return type
bool
-
PySide6.QtWidgets.QLineEdit.
maxLength
()¶ - Return type
int
See also
-
PySide6.QtWidgets.QLineEdit.
paste
()¶
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 be invalid to the current validator
, nothing happens.
-
PySide6.QtWidgets.QLineEdit.
placeholderText
()¶ - Return type
str
See also
-
PySide6.QtWidgets.QLineEdit.
redo
()¶
Redoes the last operation if redo is available
.
-
PySide6.QtWidgets.QLineEdit.
returnPressed
()¶
-
PySide6.QtWidgets.QLineEdit.
selectAll
()¶
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.
See also
-
PySide6.QtWidgets.QLineEdit.
selectedText
()¶ - Return type
str
-
PySide6.QtWidgets.QLineEdit.
selectionChanged
()¶
-
PySide6.QtWidgets.QLineEdit.
selectionEnd
()¶ - Return type
int
Returns the index of the character directly after the selection in the line edit or -1 if no text is selected.
-
PySide6.QtWidgets.QLineEdit.
selectionLength
()¶ - Return type
int
Returns the length of the selection.
See also
-
PySide6.QtWidgets.QLineEdit.
selectionStart
()¶ - Return type
int
Returns the index of the first selected character in the line edit or -1 if no text is selected.
-
PySide6.QtWidgets.QLineEdit.
setAlignment
(flag)¶ - Parameters
flag –
Alignment
See also
-
PySide6.QtWidgets.QLineEdit.
setClearButtonEnabled
(enable)¶ - Parameters
enable – bool
See also
-
PySide6.QtWidgets.QLineEdit.
setCompleter
(completer)¶ - Parameters
completer –
PySide6.QtWidgets.QCompleter
Sets this line edit to provide auto completions from the completer, c
. The completion mode is set using setCompletionMode()
.
To use a QCompleter
with a QValidator
or inputMask
, you need to ensure that the model provided to QCompleter
contains valid entries. You can use the QSortFilterProxyModel
to ensure that the QCompleter
‘s model contains only valid entries.
If c
== 0, removes the current completer, effectively disabling auto completion.
See also
-
PySide6.QtWidgets.QLineEdit.
setCursorMoveStyle
(style)¶ - Parameters
style –
CursorMoveStyle
See also
-
PySide6.QtWidgets.QLineEdit.
setCursorPosition
(arg__1)¶ - Parameters
arg__1 – int
See also
-
PySide6.QtWidgets.QLineEdit.
setDragEnabled
(b)¶ - Parameters
b – bool
See also
-
PySide6.QtWidgets.QLineEdit.
setFrame
(arg__1)¶ - Parameters
arg__1 – bool
See also
-
PySide6.QtWidgets.QLineEdit.
setInputMask
(inputMask)¶ - Parameters
inputMask – str
See also
-
PySide6.QtWidgets.QLineEdit.
setMaxLength
(arg__1)¶ - Parameters
arg__1 – int
See also
-
PySide6.QtWidgets.QLineEdit.
setModified
(arg__1)¶ - Parameters
arg__1 – bool
See also
-
PySide6.QtWidgets.QLineEdit.
setPlaceholderText
(arg__1)¶ - Parameters
arg__1 – str
See also
-
PySide6.QtWidgets.QLineEdit.
setReadOnly
(arg__1)¶ - Parameters
arg__1 – bool
See also
-
PySide6.QtWidgets.QLineEdit.
setSelection
(arg__1, arg__2)¶ - Parameters
arg__1 – int
arg__2 – int
Selects text from position start
and for length
characters. Negative lengths are allowed.
See also
-
PySide6.QtWidgets.QLineEdit.
setTextMargins
(margins)¶ - Parameters
margins –
PySide6.QtCore.QMargins
Sets the margins
around the text inside the frame.
See also textMargins()
.
-
PySide6.QtWidgets.QLineEdit.
setTextMargins
(left, top, right, bottom) - Parameters
left – int
top – int
right – int
bottom – int
Sets the margins around the text inside the frame to have the sizes left
, top
, right
, and bottom
.
See also textMargins()
.
See also
-
PySide6.QtWidgets.QLineEdit.
setValidator
(arg__1)¶ - Parameters
arg__1 –
PySide6.QtGui.QValidator
Sets the validator for values of line edit to v
.
The line edit’s and signals will only be emitted if v
validates the line edit’s content as Acceptable
. The user may change the content to any Intermediate
value during editing, but will be prevented from editing the text to a value that v
validates as Invalid
.
This allows you to constrain the text that shall finally be entered when editing is done, while leaving users with enough freedom to edit the text from one valid state to another.
If 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()
).
See also
validator()
hasAcceptableInput()
QIntValidator
QDoubleValidator
QRegularExpressionValidator
-
PySide6.QtWidgets.QLineEdit.
textChanged
(arg__1)¶ - Parameters
arg__1 – str
-
PySide6.QtWidgets.QLineEdit.
textEdited
(arg__1)¶ - Parameters
arg__1 – str
-
PySide6.QtWidgets.QLineEdit.
textMargins
()¶ - Return type
Returns the widget’s text margins.
See also
-
PySide6.QtWidgets.QLineEdit.
undo
()¶
Undoes the last operation if undo is available
. Deselects any current selection, and updates the selection start to the current cursor position.
-
PySide6.QtWidgets.QLineEdit.
validator
()¶ - Return type
Returns a pointer to the current input validator, or None
if no validator has been set.
See also
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.