QLineEdit¶
Synopsis¶
Functions¶
def
addAction
(action, position)def
addAction
(icon, position)def
alignment
()def
backspace
()def
completer
()def
createStandardContextMenu
()def
cursorBackward
(mark[, steps=1])def
cursorForward
(mark[, steps=1])def
cursorMoveStyle
()def
cursorPosition
()def
cursorPositionAt
(pos)def
cursorRect
()def
cursorWordBackward
(mark)def
cursorWordForward
(mark)def
del_
()def
deselect
()def
displayText
()def
dragEnabled
()def
echoMode
()def
end
(mark)def
getTextMargins
()def
hasAcceptableInput
()def
hasFrame
()def
hasSelectedText
()def
home
(mark)def
initStyleOption
(option)def
inputMask
()def
inputMethodQuery
(property, argument)def
insert
(arg__1)def
isClearButtonEnabled
()def
isModified
()def
isReadOnly
()def
isRedoAvailable
()def
isUndoAvailable
()def
maxLength
()def
placeholderText
()def
selectedText
()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
setTextMargins
(left, top, right, bottom)def
setTextMargins
(margins)def
setValidator
(arg__1)def
text
()def
textMargins
()def
validator
()
Slots¶
Signals¶
def
cursorPositionChanged
(arg__1, arg__2)def
editingFinished
()def
inputRejected
()def
returnPressed
()def
selectionChanged
()def
textChanged
(arg__1)def
textEdited
(arg__1)
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 avalidator()
or aninputMask()
, 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()
orinsert()
. The text is retrieved withtext()
; the displayed text (which may be different, seeEchoMode
) is retrieved withdisplayText()
. Text can be selected withsetSelection()
orselectAll()
, and the selection can becut()
,copy()
ied andpaste()
d. The text can be aligned withsetAlignment()
.When the text changes the
textChanged()
signal is emitted; when the text changes other than by callingsetText()
thetextEdited()
signal is emitted; when the cursor is moved thecursorPositionChanged()
signal is emitted; and when the Return or Enter key is pressed thereturnPressed()
signal is emitted.When editing is finished, either because the line edit lost focus or Return/Enter is pressed the
editingFinished()
signal is emitted.Note that if there is a validator set on the line edit, the
returnPressed()
/editingFinished()
signals will only be emitted if the validator returnsAcceptable
.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.
- class PySide2.QtWidgets.QLineEdit([parent=None])¶
PySide2.QtWidgets.QLineEdit(arg__1[, parent=None])
- param parent:
- param 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 theQWidget
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 theQWidget
constructor.See also
- PySide2.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
- PySide2.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
- PySide2.QtWidgets.QLineEdit.addAction(icon, position)¶
- Parameters:
icon –
PySide2.QtGui.QIcon
position –
ActionPosition
- Return type:
- PySide2.QtWidgets.QLineEdit.addAction(action, position)
- Parameters:
action –
PySide2.QtWidgets.QAction
position –
ActionPosition
Adds the
action
to the list of actions at theposition
.
- PySide2.QtWidgets.QLineEdit.alignment()¶
- Return type:
Alignment
This property holds the alignment of the line edit..
Both horizontal and vertical alignment is allowed here,
AlignJustify
will map toAlignLeft
.By default, this property contains a combination of
AlignLeft
andAlignVCenter
.See also
Alignment
- PySide2.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()
- PySide2.QtWidgets.QLineEdit.clear()¶
Clears the contents of the line edit.
- PySide2.QtWidgets.QLineEdit.completer()¶
- Return type:
Returns the current
QCompleter
that provides completions.See also
- PySide2.QtWidgets.QLineEdit.copy()¶
Copies the selected text to the clipboard, if there is any, and if
echoMode()
isNormal
.
- PySide2.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.
- PySide2.QtWidgets.QLineEdit.cursorBackward(mark[, steps=1])¶
- Parameters:
mark – bool
steps – int
Moves the cursor back
steps
characters. Ifmark
is true each character moved over is added to the selection; ifmark
is false the selection is cleared.See also
- PySide2.QtWidgets.QLineEdit.cursorForward(mark[, steps=1])¶
- Parameters:
mark – bool
steps – int
Moves the cursor forward
steps
characters. Ifmark
is true each character moved over is added to the selection; ifmark
is false the selection is cleared.See also
- PySide2.QtWidgets.QLineEdit.cursorMoveStyle()¶
- Return type:
This property holds the movement style of cursor in this line edit..
When this property is set to
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
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.
- PySide2.QtWidgets.QLineEdit.cursorPosition()¶
- Return type:
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.
- PySide2.QtWidgets.QLineEdit.cursorPositionAt(pos)¶
- Parameters:
pos –
PySide2.QtCore.QPoint
- Return type:
int
Returns the cursor position under the point
pos
.
- PySide2.QtWidgets.QLineEdit.cursorPositionChanged(arg__1, arg__2)¶
- Parameters:
arg__1 – int
arg__2 – int
- PySide2.QtWidgets.QLineEdit.cursorRect()¶
- Return type:
Returns a rectangle that includes the lineedit cursor.
- PySide2.QtWidgets.QLineEdit.cursorWordBackward(mark)¶
- Parameters:
mark – bool
Moves the cursor one word backward. If
mark
is true, the word is also selected.See also
- PySide2.QtWidgets.QLineEdit.cursorWordForward(mark)¶
- Parameters:
mark – bool
Moves the cursor one word forward. If
mark
is true, the word is also selected.See also
- PySide2.QtWidgets.QLineEdit.cut()¶
Copies the selected text to the clipboard and deletes it, if there is any, and if
echoMode()
isNormal
.If the current validator disallows deleting the selected text, will copy without deleting.
See also
- PySide2.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
- PySide2.QtWidgets.QLineEdit.deselect()¶
Deselects any selected text.
See also
- PySide2.QtWidgets.QLineEdit.displayText()¶
- Return type:
str
This property holds the displayed text..
If
echoMode
isNormal
this returns the same astext()
; ifEchoMode
isPassword
orPasswordEchoOnEdit
it returns a string of platform-dependent password mask characterstext()
. length() in size, e.g. “******”; ifEchoMode
isNoEcho
returns an empty string, “”.By default, this property contains an empty string.
See also
setEchoMode()
text()
EchoMode
- PySide2.QtWidgets.QLineEdit.dragEnabled()¶
- Return type:
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.
- PySide2.QtWidgets.QLineEdit.echoMode()¶
- Return type:
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, butQLineEdit
also supports modes that allow the entered text to be suppressed or obscured: these includeNoEcho
,Password
andPasswordEchoOnEdit
.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
EchoMode
displayText()
- PySide2.QtWidgets.QLineEdit.editingFinished()¶
- PySide2.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
- PySide2.QtWidgets.QLineEdit.getTextMargins()¶
Note
This function is deprecated.
Use
textMargins()
Returns the widget’s text margins for
left
,top
,right
, andbottom
.See also
- PySide2.QtWidgets.QLineEdit.hasAcceptableInput()¶
- Return type:
bool
This property holds whether the input satisfies the
inputMask
and the validator..By default, this property is
true
.See also
- PySide2.QtWidgets.QLineEdit.hasFrame()¶
- Return type:
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.
- PySide2.QtWidgets.QLineEdit.hasSelectedText()¶
- Return type:
bool
This property holds whether there is any text selected..
returns
true
if some or all of the text has been selected by the user; otherwise returnsfalse
.By default, this property is
false
.See also
- PySide2.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
- PySide2.QtWidgets.QLineEdit.initStyleOption(option)¶
- Parameters:
option –
PySide2.QtWidgets.QStyleOptionFrame
Initialize
option
with the values from thisQLineEdit
. This method is useful for subclasses when they need aQStyleOptionFrame
, but don’t want to fill in all the information themselves.See also
- PySide2.QtWidgets.QLineEdit.inputMask()¶
- Return type:
str
This property holds The validation input mask..
If no mask is set, returns an empty string.
Sets the
QLineEdit
‘s validation mask. Validators can be used instead of, or in conjunction with masks; seesetValidator()
.Unset the mask and return to normal
QLineEdit
operation by passing an empty string (“”).The input mask is an input template string. It can contain the following elements:
Mask Characters
Defines the
Category
of input characters that are considered valid in this positionMeta Characters
Various special meanings
Separators
All other characters are regarded as immutable separators
The following table shows the mask and meta characters that can be used in an input mask.
Mask Character
Meaning
A
character of the Letter category required, such as A-Z, a-z.
a
character of the Letter category permitted but not required.
N
character of the Letter or Number category required, such as A-Z, a-z, 0-9.
n
character of the Letter or Number category permitted but not required.
X
Any non-blank character required.
x
Any non-blank character permitted but not required.
9
character of the Number category required, e.g 0-9.
0
character of the Number category permitted but not required.
D
character of the Number category and larger than zero required, such as 1-9
d
character of the Number category and larger than zero permitted but not required, such as 1-9.
#
character of the Number category, 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.
Meta Character
Meaning
>
All following alphabetic characters are uppercased.
<
All following alphabetic characters are lowercased.
!
Switch off case conversion.
;c
Terminates the input mask and sets the blank character to c .
[ ] { }
Reserved.
\
Use
\
to escape the special characters listed above to use them as separators.When created or cleared, the line edit will be filled with a copy of the input mask string where the meta characters have been removed, and the mask characters have been replaced with the blank character (by default, a
space
).When an input mask is set, the
text()
method returns a modified copy of the line edit content where all the blank characters have been removed. The unmodified content can be read usingdisplayText()
.The
hasAcceptableInput()
method returns false if the current content of the line edit does not fulfil the requirements of the input mask.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
maxLength
isLetter()
isNumber()
digitValue()
- PySide2.QtWidgets.QLineEdit.inputMethodQuery(property, argument)¶
- Parameters:
property –
InputMethodQuery
argument – object
- Return type:
object
- PySide2.QtWidgets.QLineEdit.inputRejected()¶
- PySide2.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.
- PySide2.QtWidgets.QLineEdit.isClearButtonEnabled()¶
- Return type:
bool
This property holds Whether the line edit displays a clear button when it is not empty..
If enabled, the line edit displays a trailing clear button when it contains some text, otherwise the line edit does not show a clear button (the default).
See also
- PySide2.QtWidgets.QLineEdit.isModified()¶
- Return type:
bool
This property holds whether the line edit’s contents has been modified by the user..
The modified flag is never read by
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
setText()
resets the modified flag to false.
- PySide2.QtWidgets.QLineEdit.isReadOnly()¶
- Return type:
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
echoMode()
isNormal
), but cannot edit it.QLineEdit
does not show a cursor in read-only mode.By default, this property is
false
.See also
- PySide2.QtWidgets.QLineEdit.isRedoAvailable()¶
- Return type:
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
.
- PySide2.QtWidgets.QLineEdit.isUndoAvailable()¶
- Return type:
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
.
- PySide2.QtWidgets.QLineEdit.maxLength()¶
- Return type:
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
- PySide2.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.
- PySide2.QtWidgets.QLineEdit.placeholderText()¶
- Return type:
str
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 line edit is empty.
Normally, an empty line edit shows the placeholder text even when it has focus. However, if the content is horizontally centered, the placeholder text is not displayed under the cursor when the line edit has focus.
By default, this property contains an empty string.
See also
- PySide2.QtWidgets.QLineEdit.redo()¶
Redoes the last operation if redo is
available
.
- PySide2.QtWidgets.QLineEdit.returnPressed()¶
- PySide2.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
- PySide2.QtWidgets.QLineEdit.selectedText()¶
- Return type:
str
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.
See also
- PySide2.QtWidgets.QLineEdit.selectionChanged()¶
- PySide2.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.
- PySide2.QtWidgets.QLineEdit.selectionLength()¶
- Return type:
int
Returns the length of the selection.
See also
- PySide2.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.
- PySide2.QtWidgets.QLineEdit.setAlignment(flag)¶
- Parameters:
flag –
Alignment
This property holds the alignment of the line edit..
Both horizontal and vertical alignment is allowed here,
AlignJustify
will map toAlignLeft
.By default, this property contains a combination of
AlignLeft
andAlignVCenter
.See also
Alignment
- PySide2.QtWidgets.QLineEdit.setClearButtonEnabled(enable)¶
- Parameters:
enable – bool
This property holds Whether the line edit displays a clear button when it is not empty..
If enabled, the line edit displays a trailing clear button when it contains some text, otherwise the line edit does not show a clear button (the default).
See also
- PySide2.QtWidgets.QLineEdit.setCompleter(completer)¶
- Parameters:
completer –
PySide2.QtWidgets.QCompleter
Sets this line edit to provide auto completions from the completer,
c
. The completion mode is set usingsetCompletionMode()
.To use a
QCompleter
with aQValidator
orinputMask
, you need to ensure that the model provided toQCompleter
contains valid entries. You can use theQSortFilterProxyModel
to ensure that theQCompleter
‘s model contains only valid entries.If
c
== 0, removes the current completer, effectively disabling auto completion.See also
- PySide2.QtWidgets.QLineEdit.setCursorMoveStyle(style)¶
- Parameters:
style –
CursorMoveStyle
This property holds the movement style of cursor in this line edit..
When this property is set to
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
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.
- PySide2.QtWidgets.QLineEdit.setCursorPosition(arg__1)¶
- Parameters:
arg__1 – 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.
- PySide2.QtWidgets.QLineEdit.setDragEnabled(b)¶
- Parameters:
b – 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.
- PySide2.QtWidgets.QLineEdit.setEchoMode(arg__1)¶
- Parameters:
arg__1 –
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, butQLineEdit
also supports modes that allow the entered text to be suppressed or obscured: these includeNoEcho
,Password
andPasswordEchoOnEdit
.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
EchoMode
displayText()
- PySide2.QtWidgets.QLineEdit.setFrame(arg__1)¶
- Parameters:
arg__1 – 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.
- PySide2.QtWidgets.QLineEdit.setInputMask(inputMask)¶
- Parameters:
inputMask – str
This property holds The validation input mask..
If no mask is set, returns an empty string.
Sets the
QLineEdit
‘s validation mask. Validators can be used instead of, or in conjunction with masks; seesetValidator()
.Unset the mask and return to normal
QLineEdit
operation by passing an empty string (“”).The input mask is an input template string. It can contain the following elements:
Mask Characters
Defines the
Category
of input characters that are considered valid in this positionMeta Characters
Various special meanings
Separators
All other characters are regarded as immutable separators
The following table shows the mask and meta characters that can be used in an input mask.
Mask Character
Meaning
A
character of the Letter category required, such as A-Z, a-z.
a
character of the Letter category permitted but not required.
N
character of the Letter or Number category required, such as A-Z, a-z, 0-9.
n
character of the Letter or Number category permitted but not required.
X
Any non-blank character required.
x
Any non-blank character permitted but not required.
9
character of the Number category required, e.g 0-9.
0
character of the Number category permitted but not required.
D
character of the Number category and larger than zero required, such as 1-9
d
character of the Number category and larger than zero permitted but not required, such as 1-9.
#
character of the Number category, 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.
Meta Character
Meaning
>
All following alphabetic characters are uppercased.
<
All following alphabetic characters are lowercased.
!
Switch off case conversion.
;c
Terminates the input mask and sets the blank character to c .
[ ] { }
Reserved.
\
Use
\
to escape the special characters listed above to use them as separators.When created or cleared, the line edit will be filled with a copy of the input mask string where the meta characters have been removed, and the mask characters have been replaced with the blank character (by default, a
space
).When an input mask is set, the
text()
method returns a modified copy of the line edit content where all the blank characters have been removed. The unmodified content can be read usingdisplayText()
.The
hasAcceptableInput()
method returns false if the current content of the line edit does not fulfil the requirements of the input mask.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
maxLength
isLetter()
isNumber()
digitValue()
- PySide2.QtWidgets.QLineEdit.setMaxLength(arg__1)¶
- Parameters:
arg__1 – 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
- PySide2.QtWidgets.QLineEdit.setModified(arg__1)¶
- Parameters:
arg__1 – bool
This property holds whether the line edit’s contents has been modified by the user..
The modified flag is never read by
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
setText()
resets the modified flag to false.
- PySide2.QtWidgets.QLineEdit.setPlaceholderText(arg__1)¶
- Parameters:
arg__1 – str
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 line edit is empty.
Normally, an empty line edit shows the placeholder text even when it has focus. However, if the content is horizontally centered, the placeholder text is not displayed under the cursor when the line edit has focus.
By default, this property contains an empty string.
See also
- PySide2.QtWidgets.QLineEdit.setReadOnly(arg__1)¶
- Parameters:
arg__1 – 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
echoMode()
isNormal
), but cannot edit it.QLineEdit
does not show a cursor in read-only mode.By default, this property is
false
.See also
- PySide2.QtWidgets.QLineEdit.setSelection(arg__1, arg__2)¶
- Parameters:
arg__1 – int
arg__2 – int
Selects text from position
start
and forlength
characters. Negative lengths are allowed.See also
- PySide2.QtWidgets.QLineEdit.setText(arg__1)¶
- Parameters:
arg__1 – str
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 .The text is truncated to
maxLength()
length.By default, this property contains an empty string.
- PySide2.QtWidgets.QLineEdit.setTextMargins(margins)¶
- Parameters:
margins –
PySide2.QtCore.QMargins
Sets the
margins
around the text inside the frame.See also
textMargins()
.
- PySide2.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
, andbottom
.See also
textMargins()
.See also
- PySide2.QtWidgets.QLineEdit.setValidator(arg__1)¶
- Parameters:
arg__1 –
PySide2.QtGui.QValidator
Sets the validator for values of line edit to
v
.The line edit’s
returnPressed()
andeditingFinished()
signals will only be emitted ifv
validates the line edit’s content asAcceptable
. The user may change the content to anyIntermediate
value during editing, but will be prevented from editing the text to a value thatv
validates asInvalid
.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 tomaxLength()
).See also
validator()
hasAcceptableInput()
QIntValidator
QDoubleValidator
QRegExpValidator
- PySide2.QtWidgets.QLineEdit.text()¶
- Return type:
str
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 .The text is truncated to
maxLength()
length.By default, this property contains an empty string.
- PySide2.QtWidgets.QLineEdit.textChanged(arg__1)¶
- Parameters:
arg__1 – str
- PySide2.QtWidgets.QLineEdit.textEdited(arg__1)¶
- Parameters:
arg__1 – str
- PySide2.QtWidgets.QLineEdit.textMargins()¶
- Return type:
Returns the widget’s text margins.
See also
- PySide2.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.
- PySide2.QtWidgets.QLineEdit.validator()¶
- Return type:
Returns a pointer to the current input validator, or
None
if no validator has been set.See also
© 2022 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.