Home · Overviews · Examples 

QLineEdit Class Reference
[com.trolltech.qt.gui module]

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

Inherits QWidget.


Detailed Description

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.

KeypressAction
Left ArrowMoves the cursor one character to the left.
Shift+Left ArrowMoves and selects text one character to the left.
Right ArrowMoves the cursor one character to the right.
Shift+Right ArrowMoves and selects text one character to the right.
HomeMoves the cursor to the beginning of the line.
EndMoves the cursor to the end of the line.
BackspaceDeletes the character to the left of the cursor.
Ctrl+BackspaceDeletes the word to the left of the cursor.
DeleteDeletes the character to the right of the cursor.
Ctrl+DeleteDeletes the word to the right of the cursor.
Ctrl+ASelect all.
Ctrl+CCopies the selected text to the clipboard.
Ctrl+InsertCopies the selected text to the clipboard.
Ctrl+KDeletes to the end of the line.
Ctrl+VPastes the clipboard text into line edit.
Shift+InsertPastes the clipboard text into line edit.
Ctrl+XDeletes the selected text and copies it to the clipboard.
Shift+DeleteDeletes the selected text and copies it to the clipboard.
Ctrl+ZUndoes the last operation.
Ctrl+YRedoes the last undone operation.

Any other key sequence that represents a valid character, will cause the character to be inserted into the line edit.

Screenshot of a Macintosh style line editA line edit shown in the Macintosh widget style.
Screenshot of a Windows XP style line editA line edit shown in the Windows XP widget style.
Screenshot of a Plastique style line editA 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