Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The QLineEdit widget is a one-line text editor. More...
#include <qlineedit.h>
Inherits QFrame.
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 field can be constrained to maxLength(), or the value can be arbitrarily constrained using a validator().
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(), copy()ied and paste()d. The text can be aligned with setAlignment().
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 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. A right mouse button menu presents some of the editing commands to the user.
Keypress | Action |
---|---|
Left Arrow | moves the cursor one character to the left. |
Right Arrow | moves the cursor one character to the right. |
Backspace | deletes the character to the left of the cursor. |
Ctrl+Backspace | Delete the word to the left of the cursor |
Delete | Delete the character to the right of the cursor |
Ctrl+Delete | Delete the word to the right of the cursor |
Home | moves the cursor to the beginning of the line. |
End | moves the cursor to the end of the line. |
Delete | deletes the character to the right of the cursor. |
Shift+Left Arrow | moves and selects text one character to the left. |
Shift+Right Arrow | moves and selects text one character to the right. |
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 | redoes the last undone operation. |
Any other key sequence, that represents a valid character, will cause the character to be inserted into the line.
See also QTextEdit, QLabel, QComboBox, GUI Design Handbook: Field, Entry, and Basic Widgets.
This enum type describes how a line edit should display its contents.
See also echoMode and echoMode.
The maximum text length is set to 32767 characters.
The parent and name arguments are sent to the QWidget constructor.
The cursor position is set to the end of the line and the maximum text length to 32767 characters.
The parent and name arguments are sent to the QWidget constructor.
Returns the alignment of the line edit. See the "alignment" property for details.
See also del().
See also cursorForward().
See also cursorBackward().
For compatibilty with older applications only. Use cursorBackward() instead.
See also cursorBackward().
Returns the current cursor position for this line edit. See the "cursorPosition" property for details.
Use cursorForward() instead.
See also cursorForward().
See also cursorWordForward().
See also cursorWordBackward().
If the current validator disallows deleting the selected text, cut() will copy it but not delete it.
See also backspace().
See also setSelection() and selectAll().
Returns the displayed text. See the "displayText" property for details.
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.
Returns the line edit's echo mode. See the "echoMode" property for details.
Returns TRUE if the line edit has been edited; otherwise returns FALSE. See the "edited" property for details.
See also home().
Returns TRUE if the line edit draws itself with a frame; otherwise returns FALSE. See the "frame" property for details.
See also setSelection().
Returns TRUE if part of the text has been selected by the user (e.g. by clicking and dragging); otherwise returns FALSE. See the "hasMarkedText" property for details.
Returns TRUE if there is any text selected; otherwise returns FALSE. See the "hasSelectedText" property for details.
See also end().
Returns TRUE if the line edit is read only; otherwise returns FALSE. See the "readOnly" property for details.
Returns TRUE if redo is available; otherwise returns FALSE. See the "redoAvailable" property for details.
Returns TRUE if undo is available; otherwise returns FALSE. See the "undoAvailable" property for details.
If Return or Enter is pressed and the current text is valid (or can be made valid by the validator), the signal returnPressed() is emitted.
The default key bindings are listed in the detailed description.
Reimplemented from QWidget.
This signal is emitted when the line edit has lost focus.
See also focus, QWidget::focusInEvent(), and QWidget::focusOutEvent().
Returns the text selected by the user (e.g. by clicking and dragging), or QString::null if no text is selected. See the "markedText" property for details.
Returns the maximum permitted length of the text. See the "maxLength" property for details.
The width returned is enough for at least one character.
Reimplemented from QWidget.
If the end result is not acceptable for the current validator, nothing happens.
Repaints all characters from from to to. If cursorPos is between from and to, ensures that cursorPos is visible.
This signal is emitted when the Return or Enter key is pressed. Note that if there is a validator set on the line edit, the returnPressed() signal will only be emitted if the validator returns Acceptable.
Example: popup/popup.cpp.
See also setSelection() and deselect().
Returns the selected text. See the "selectedText" property for details.
This signal is emitted whenever the selection changes.
See also hasSelectedText and selectedText.
Sets the alignment of the line edit to flag. See the "alignment" property for details.
Sets the current cursor position for this line edit. See the "cursorPosition" property for details.
Sets whether the lineedit starts a drag if the user presses and moves the mouse on some selected text to b. See the "dragEnabled" property for details.
Sets the line edit's echo mode. See the "echoMode" property for details.
Sets whether the line edit has been edited. See the "edited" property for details.
Sets whether the line edit draws itself with a frame. See the "frame" property for details.
Sets the maximum permitted length of the text. See the "maxLength" property for details.
Sets whether the line edit is read only. See the "readOnly" property for details.
See also deselect(), selectAll(), and getSelection().
Sets the line edit's text. See the "text" property for details.
If v == 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()).
See also validator() and QValidator.
Examples: lineedits/lineedits.cpp and wizard/wizard.cpp.
The width returned, in pixels, is usually enough for about 15 to 20 characters.
Example: addressbook/centralwidget.cpp.
Returns the line edit's text. See the "text" property for details.
This signal is emitted whenever the text changes. The argument is the new text.
Examples: wizard/wizard.cpp and xform/xform.cpp.
Linebreaks in newText are converted to spaces, and the text is truncated to maxLength() before its validity is tested.
Repaints and emits textChanged() if appropriate.
See also setValidator().
Example: wizard/wizard.cpp.
This property holds the alignment of the line edit.
Possible Values are Qt::AlignAuto, Qt::AlignLeft, Qt::AlignRight and Qt::AlignHCenter.
Attempting to set the alignment to an illegal flag combination does nothing.
See also Qt::AlignmentFlags.
Set this property's value with setAlignment() and get this property's value with alignment().
This property holds the current cursor position for this line edit.
Setting the cursor position causes a repaint when appropriate.
Set this property's value with setCursorPosition() and get this property's value with cursorPosition().
This property holds the displayed text.
If EchoMode is Normal this returns the same as text(); if EchoMode is Password it returns a string of asterisks the text().length() characters long, e.g. "******"; if EchoMode is NoEcho returns an empty string, "".
See also echoMode, text, and EchoMode.
Get this property's value with displayText().
This property holds whether the lineedit starts a drag if the user presses and moves the mouse on some selected text.
Set this property's value with setDragEnabled() and get this property's value with dragEnabled().
This property holds the line edit's echo mode.
The initial setting is Normal, but QLineEdit also supports NoEcho and Password modes.
The widget's display and the ability to copy or drag the text is affected by this setting.
See also EchoMode and displayText.
Set this property's value with setEchoMode() and get this property's value with echoMode().
This property holds whether the line edit has been edited.
The edited 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 cannot find the default at once. Just start the line edit without the best default; when the default is known, check the edited() return value and set the line edit's contents if the user has not started editing the line edit.
Calling setText() resets the edited flag to FALSE.
Set this property's value with setEdited() and get this property's value with edited().
This property holds whether the line edit draws itself with a frame.
If enabled (the default) the line edit draws itself inside a two-pixel frame, otherwise the line edit draws itself without any frame.
Set this property's value with setFrame() and get this property's value with frame().
This property holds whether part of the text has been selected by the user (e.g. by clicking and dragging).
Get this property's value with hasMarkedText().
See also selectedText.
This property holds whether there is any text selected.
hasSelectedText() returns TRUE if some or all of the text has been selected by the user (e.g. by clicking and dragging); otherwise returns FALSE.
See also selectedText.
Get this property's value with hasSelectedText().
This property holds the text selected by the user (e.g. by clicking and dragging), or QString::null if no text is selected.
Get this property's value with markedText().
See also hasSelectedText.
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.
Set this property's value with setMaxLength() and get this property's value with maxLength().
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, but cannot edit it.
QLineEdit does not show a cursor in read-only mode.
See also enabled.
Set this property's value with setReadOnly() and get this property's value with isReadOnly().
This property holds whether redo is available.
Get this property's value with isRedoAvailable().
This property holds the selected text.
If there is no selected text this property's value is QString::null.
See also hasSelectedText.
Get this property's value with selectedText().
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 edited property to FALSE. The text is not validated when inserted with setText().
The text is truncated to maxLength() length.
Set this property's value with setText() and get this property's value with text().
This property holds whether undo is available.
Get this property's value with isUndoAvailable().
This file is part of the Qt toolkit. Copyright © 1995-2003 Trolltech. All Rights Reserved.
Copyright © 2003 Trolltech | Trademarks | Qt version 3.1.2
|