Skip to content

QLineEdit


QLineEdit is a widget that allows the user to enter and edit text. It provides a single line for the user to type in text.

Parameters:

Name Type Description Default
text str

The initial text to display in the line edit.

None

Signals

  • cursorPositionChanged: Emitted when the cursor position changes.
  • editingFinished: Emitted when the editing is finished.
  • returnPressed: Emitted when the return key is pressed.
  • textChanged: Emitted when the text changes.
  • textEdited: Emitted when the text is edited.

Methods


Examples


line_edit = QtWidgets.QLineEdit("Enter text here")
print(line_edit.text())
print(line_edit.isModified())
'Enter text here'
False

Now the user modifies the text in the line edit to 'New text'.
print(line_edit.modified())
print(line_edit.text())
True
'New text'



clear()

Clear the text in the line edit.


copy()

Copy the selected text in the line edit to the clipboard.


cut()

Cut the selected text in the line edit to the clipboard.


isModified()

Check if the text in the line edit has been modified by the user. setText resets the modified flag.

Returns:

Type Description
bool

True if the text has been modified, False otherwise.


isReadOnly()

Check if the line edit is read-only.

Returns:

Type Description
bool

True if the line edit is read-only, False otherwise.


maxLength()

Get the maximum length of the text in the line edit.

Returns:

Type Description
int

The maximum length of the text in the line edit.


paste()

Paste the text from the clipboard to the line edit.


placeholderText()

Get the placeholder text displayed in the line edit when it is empty.

Returns:

Type Description
str

The placeholder text.


redo()

Redo the last operation in the line edit.


setMaxLength(length)

Set the maximum length of the text in the line edit.

Parameters:

Name Type Description Default
length int

The maximum length of the text in the line edit.

required


setPlaceholderText(text)

Set the placeholder text displayed in the line edit when it is empty. The placeholder text is displayed in gray.

Parameters:

Name Type Description Default
text str

The placeholder text.

required


setReadOnly(read_only)

Set the line edit to read-only. If the line edit is read-only, the user cannot edit the text.

Parameters:

Name Type Description Default
read_only bool

True to set the line edit to read-only, False otherwise.

required


setText(text)

Set the content of the line edit to the specified text.

Parameters:

Name Type Description Default
text str

The text to set in the line edit.

required


text()

Get the text in the line edit.

Returns:

Type Description
str

The text in the line edit.


undo()

Undo the last operation in the line edit.