![]() |
Home · Overviews · Examples |
The QLineEdit widget is a one-line text editor. More...
Inherits QWidget.
The 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 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.
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, copyied and pasted. 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 textEdited signal is emitted; when the cursor is moved the cursorPositionChanged signal is emitted; and when the Return or Enter key is pressed the returnPressed 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 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 QTextEdit, QLabel, QComboBox, GUI Design Handbook: Field, Entry, and Line Edits Example.
Copyright © 2007 Trolltech | Trademarks | Qt Jambi 4.3.2_01 |