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.
.PP
By changing the echoMode() of a line edit, it can also be used as a "write-only" field, for inputs such as passwords.
.PP
The length of the text can be constrained to maxLength(). The text can be arbitrarily constrained using a validator() or an inputMask(), or both.
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().
.PP
When the text changes the textChanged() signal is emitted; when the Return or Enter key is pressed the returnPressed() signal is emitted. Note that if there is a validator set on the line edit, the returnPressed() signal will only be emitted if the validator returns \fCAcceptable\fR.
.PP
By default, QLineEdits have a frame as specified by the Windows and Motif style guides; you can turn it off by calling setFrame(FALSE).
.PP
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. <center>.nf
.TS
l - l. 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 Moves the cursor to the beginning of the line. Ctrl+B Moves the cursor one character to the left. Ctrl+C Copies the selected text to the clipboard. (Windows also supports Ctrl+Insert for this operation.) Ctrl+D Deletes the character to the right of the cursor. Ctrl+E Moves the cursor to the end of the line. Ctrl+F Moves the cursor one character to the right. Ctrl+H Deletes the character to the left of the cursor. Ctrl+K Deletes to the end of the line. Ctrl+V Pastes the clipboard text into line edit. (Windows also supports Shift+Insert for this operation.) Ctrl+X Deletes the selected text and copies it to the clipboard. (Windows also supports Shift+Delete for this operation.) Ctrl+Z Undoes the last operation. Ctrl+Y
.TE
.fi
</center>
.PP
Any other key sequence that represents a valid character, will cause the character to be inserted into the line edit.
Constructs a line edit with an input \fIinputMask\fR and the text \fIcontents\fR.
.PP
The cursor position is set to the end of the line and the maximum text length is set to the length of the mask (the number of mask characters and separators).
Returns the alignment of the line edit. See the "alignment" property for details.
.SH "void 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.
This function is called to create the popup menu which is shown when the user clicks on the line edit with the right mouse button. If you want to create a custom popup menu, reimplement this function and return the popup menu you create. The popup menu's ownership is transferred to the caller.
Moves the cursor back \fIsteps\fR characters. If \fImark\fR is TRUE each character moved over is added to the selection; if \fImark\fR is FALSE the selection is cleared.
Moves the cursor forward \fIsteps\fR characters. If \fImark\fR is TRUE each character moved over is added to the selection; if \fImark\fR is FALSE the selection is cleared.
.PP
See also cursorBackward().
.SH "int QLineEdit::cursorPosition () const"
Returns the current cursor position for this line edit. See the "cursorPosition" property for details.
.SH "void QLineEdit::cursorWordBackward ( bool mark )"
Moves the cursor one word backward. If \fImark\fR is TRUE, the word is also selected.
.PP
See also cursorWordForward().
.SH "void QLineEdit::cursorWordForward ( bool mark )"
Moves the cursor one word forward. If \fImark\fR is TRUE, the word is also selected.
.PP
See also cursorWordBackward().
.SH "void QLineEdit::cut ()\fC [virtual slot]\fR"
Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode() is Normal.
.PP
If the current validator disallows deleting the selected text, cut() will copy without deleting.
.PP
See also copy(), paste(), and setValidator().
.SH "void 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.
Returns the displayed text. See the "displayText" property for details.
.SH "bool QLineEdit::dragEnabled () const"
Returns TRUE if the lineedit starts a drag if the user presses and moves the mouse on some selected text; otherwise returns FALSE. See the "dragEnabled" property for details.
.SH "EchoMode QLineEdit::echoMode () const"
Returns the line edit's echo mode. See the "echoMode" property for details.
.SH "bool QLineEdit::edited () const"
Returns TRUE if the line edit has been edited. Use modified instead; otherwise returns FALSE. See the "edited" property for details.
.SH "void QLineEdit::end ( bool mark )"
Moves the text cursor to the end of the line unless it is already there. If \fImark\fR is TRUE, text is selected towards the last position; otherwise, any selected text is unselected if the cursor is moved.
.PP
See also home().
.SH "bool QLineEdit::frame () const"
Returns TRUE if the line edit draws itself with a frame; otherwise returns FALSE. See the "frame" property for details.
.SH "bool QLineEdit::getSelection ( int * start, int * end )"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code. use selectedText(), selectionStart()
.SH "bool QLineEdit::hasAcceptableInput () const"
Returns TRUE if the input satisfies the inputMask and the validator; otherwise returns FALSE. See the "acceptableInput" property for details.
.SH "bool QLineEdit::hasSelectedText () const"
Returns TRUE if there is any text selected; otherwise returns FALSE. See the "hasSelectedText" property for details.
.SH "void QLineEdit::home ( bool mark )"
Moves the text cursor to the beginning of the line unless it is already there. If \fImark\fR is TRUE, text is selected towards the first position; otherwise, any selected text is unselected if the cursor is moved.
This signal is emitted when the Return or Enter key is pressed. Note that if there is a validator() or inputMask() set on the line edit, the returnPressed() signal will only be emitted if the input follows the inputMask() and the validator() returns \fCAcceptable\fR.
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.
This signal is emitted whenever the selection changes.
.PP
See also hasSelectedText and selectedText.
.SH "int QLineEdit::selectionStart () const"
selectionStart() returns the index of the first selected character in the line edit or -1 if no text is selected.
.PP
See also selectedText.
.SH "void QLineEdit::setAlignment ( int flag )\fC [virtual slot]\fR"
Sets the alignment of the line edit to \fIflag\fR. See the "alignment" property for details.
.SH "void QLineEdit::setCursorPosition ( int )\fC [virtual slot]\fR"
Sets the current cursor position for this line edit. See the "cursorPosition" property for details.
.SH "void QLineEdit::setDragEnabled ( bool b )\fC [virtual slot]\fR"
Sets whether the lineedit starts a drag if the user presses and moves the mouse on some selected text to \fIb\fR. See the "dragEnabled" property for details.
Sets this line edit to only accept input that the validator, \fIv\fR, will accept. This allows you to place any arbitrary constraints on the text which may be entered.
.PP
If \fIv\fR == 0, setValidator() removes the current input validator. The initial setting is to have no input validator (i.e. any input is accepted up to maxLength()).
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code. Use setText(), setCursorPosition() and setSelection() instead.
If EchoMode is Normal this returns the same as text(); if EchoMode is Password it returns a string of asterisks text().length() characters long, e.g. "******"; if EchoMode is NoEcho returns an empty string, "".
.PP
See also echoMode, text, and EchoMode.
.PP
Get this property's value with displayText().
.SH "bool dragEnabled"
This property holds whether the lineedit starts a drag if the user presses and moves the mouse on some selected text.
.PP
Set this property's value with setDragEnabled() and get this property's value with dragEnabled().
.SH "EchoMode echoMode"
This property holds the line edit's echo mode.
.PP
The initial setting is Normal, but QLineEdit also supports NoEcho and Password modes.
.PP
The widget's display and the ability to copy or drag the text is affected by this setting.
.PP
See also EchoMode and displayText.
.PP
Set this property's value with setEchoMode() and get this property's value with echoMode().
.SH "bool edited"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
This property holds whether the line edit has been edited. Use modified instead.
.PP
Set this property's value with setEdited() and get this property's value with edited().
.SH "bool frame"
This property holds whether the line edit draws itself with a frame.
.PP
If enabled (the default) the line edit draws itself inside a two-pixel frame, otherwise the line edit draws itself without any frame.
.PP
Set this property's value with setFrame() and get this property's value with frame().
.SH "bool hasSelectedText"
This property holds whether there is any text selected.
.PP
hasSelectedText() returns TRUE if some or all of the text has been selected by the user; otherwise returns FALSE.
l - l. Character Meaning ASCII alphabetic character required. A-Z, a-z. ASCII alphabetic character permitted but not required. ASCII alphanumeric character required. A-Z, a-z, 0-9. ASCII alphanumeric character permitted but not required. Any character required. x Any character permitted but not required. ASCII digit required. 0-9. ASCII digit permitted but not required. ASCII digit required. 1-9. ASCII digit permitted but not required (1-9). ASCII digit or plus/minus sign permitted but not required. All following alphabetic characters are uppercased. All following alphabetic characters are lowercased. Switch off case conversion. Use
The mask consists of a string of mask characters and separators, optionally followed by a semi-colon and the character used for blanks: the blank characters are always removed from the text after editing. The default blank character is space.
.PP
Examples:
.)l
<center>.nf
.TS
l - l. Mask Notes IP address; blanks are ISO Date; blanks are License number; blanks are
.TE
.fi
</center>
.PP
To get range control (e.g. for an IP address) use masks together with validators.
.PP
See also maxLength.
.PP
Set this property's value with setInputMask() and get this property's value with inputMask().
.SH "int maxLength"
This property holds the maximum permitted length of the text.
.PP
If the text is too long, it is truncated at the limit.
.PP
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.
.PP
If the line edit has an input mask, the mask defines the maximum string length.
.PP
See also inputMask.
.PP
Set this property's value with setMaxLength() and get this property's value with maxLength().
.SH "bool modified"
This property holds whether the line edit's contents has been modified by the user.
.PP
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.
.PP
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.
.PP
Calling clearModified() or setText() resets the modified flag to FALSE.
.PP
Get this property's value with isModified().
.SH "bool readOnly"
This property holds whether the line edit is read only.
.PP
In read-only mode, the user can still copy the text to the clipboard or drag-and-drop the text (if echoMode() is Normal), but cannot edit it.
.PP
QLineEdit does not show a cursor in read-only mode.
.PP
See also enabled.
.PP
Set this property's value with setReadOnly() and get this property's value with isReadOnly().
Note that 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 setText().
.PP
The text is truncated to maxLength() length.
.PP
See also insert().
.PP
Set this property's value with setText() and get this property's value with text().