The QLineEdit widget is a one-line text editor. More...
#include <qlineedit.h>
Inherits QWidget.
Type | Name | READ | WRITE | Options |
---|---|---|---|---|
QString | text | text | setText | |
int | maxLength | maxLength | setMaxLength | |
bool | frame | frame | setFrame | |
EchoMode | echoMode | echoMode | setEchoMode | |
QString | displayText | displayText | ||
int | cursorPosition | cursorPosition | setCursorPosition | |
Alignment | alignment | alignment | setAlignment | |
bool | edited | edited | setEdited | |
bool | hasMarkedText | hasMarkedText | ||
QString | markedText | markedText |
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 & redo, cut & paste, and drag & 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 a maxLength(), or the value can be arbitrarily constrained by setting a validator().
A closely related class is QMultiLineEdit which allows multi-line editing.
The default QLineEdit object has its own frame as specified by the Windows/Motif style guides, you can turn off the frame by calling setFrame( FALSE ).
The default key bindings are described in keyPressEvent(). A right-mouse-button menu presents a number of the editing commands to the user.
See also QMultiLineEdit, QLabel, QComboBox, GUI Design Handbook: Field, Entry, and GUI Design Handbook: Field, Required.
Examples: xform/xform.cpp layout/layout.cpp popup/popup.cpp
Normal
- display characters as they are entered. This is
the default.
NoEcho
- do not display anything. This may be appropriate
for passwords where even the length of the password should
be kept secret.
Password
- display asterisks instead of the characters
actually entered.
See also setEchoMode(), echoMode() and QMultiLineEdit::EchoMode.
Constructs a line edit with no text.
The maximum text length is set to 32767 characters.
The parent and name arguments are sent to the QWidget constructor.
See also setText() and setMaxLength().
Constructs a line edit containing the text contents.
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.
See also text() and setMaxLength().
Destructs the line edit.
Returns the alignment of the line edit. Possible Values are Qt::AlignLeft, Qt::AlignRight and Qt::Align(H)Center.
See also setAlignment() and Qt::AlignmentFlags.
Deletes the character to the left of the text cursor and moves the cursor one position to the left. If a text has been marked by the user (e.g. by clicking and dragging) the cursor will be put at the beginning of the marked text and the marked text will be removed.
See also del().
[slot]
Syntactic sugar for setText( "" ), provided to match no-argument signals.
[slot]
This slot is equivalent to setValidator( 0 ).
Copies the marked text to the clipboard, if there is any and if echoMode() is Normal.
Moves the cursor leftwards one or more characters.
See also cursorRight().
Returns the current cursor position for this line edit.
See also setCursorPosition().
Moves the cursor rightwards one or more characters.
See also cursorLeft().
Moves the cursor one word to the left. If mark is TRUE, the text is marked.
See also cursorWordForward().
Moves the cursor one word to the right. If mark is TRUE, the text is marked.
See also cursorWordBackward().
Copies the marked text to the clipboard and deletes it, if there is any.
If the current validator disallows deleting the marked text, cut() will copy it but not delete it.
Deletes the character on the right side of the text cursor. If a text has been marked by the user (e.g. by clicking and dragging) the cursor will be put at the beginning of the marked text and the marked text will be removed.
See also backspace().
[slot]
Deselects all text (i.e. removes marking) and leaves the cursor at the current position.
Returns the text that is displayed. This is normally the same as text(), but can be e.g. "*****" if EchoMode is Password or "" if it is NoEcho.
See also setEchoMode(), text() and EchoMode.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
Returns the echo mode of the line edit.
See also setEchoMode() and EchoMode.
Returns the edited flag of the line edit. If this returns FALSE, the line edit's contents have not been changed since the construction of the QLineEdit (or the last call to either setText() or setEdited( FALSE ), if any). If it returns true, the contents have been edited, or setEdited( TRUE ) has been called.
See also setEdited().
Moves the text cursor to the right end of the line. If mark is TRUE text will be marked towards the last position, if not any marked text will be unmarked if the cursor is moved.
See also home().
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QObject.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
Returns TRUE if the line edit draws itself inside a frame, FALSE if it draws itself without any frame.
The default is to use a frame.
See also setFrame().
Returns TRUE if part of the text has been marked by the user (e.g. by clicking and dragging).
See also markedText().
Moves the text cursor to the left end of the line. If mark is TRUE text will be marked towards the first position, if not any marked text will be unmarked if the cursor is moved.
See also end().
[slot]
Removes any selected text, inserts newText, validates the result and if it is valid, sets it as the new contents of the line edit.
Returns whether the line-edit is read-only.
See also setReadOnly().
[virtual protected]
Converts a key press into a line edit action.
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:
All other keys with valid ASCII codes insert themselves into the line.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
Returns the text marked by the user (e.g. by clicking and dragging), or a null string if no text is marked.
See also hasMarkedText().
Returns the maximum permitted length of the text in the editor.
See also setMaxLength().
[virtual]
Returns a minimum size for the line edit.
The width returned is enough for at least one character.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
Inserts the clipboard's text at the cursor position, deleting any previous marked text.
If the end result is not acceptable for the current validator, nothing happens.
[protected]
Repaints all characters from from to to. If cursorPos is between from and to, ensures that cursorPos is visible.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[signal]
This signal is emitted when the return or enter key is pressed.
[slot]
Selects all text (i.e. marks it) and moves the cursor to the end. This is useful when a default value has been inserted, since if the user types before clicking on the widget the selected text will be erased.
Sets the alignment of the line edit. Possible Values are Qt::AlignLeft, Qt::AlignRight and Qt::Align(H)Center - see Qt::AlignmentFlags.
See also alignment().
[virtual]
Sets the cursor position for this line edit to newPos and repaints accordingly.
See also cursorPosition().
Sets the echo mode of the line edit widget.
The echo modes available are:
Normal
- display characters as they are entered. This is
the default.
NoEcho
- do not display anything. This may be appropriate
for passwords where even the length of the password should
be kept secret.
Password
- display asterisks instead of the characters
actually entered.
The widget's display, and the ability to copy or drag the text is affected by this setting.
See also echoMode(), EchoMode and displayText().
Sets the edited flag of this line edit to on. The edited flag is never read by QLineEdit, and is changed to TRUE whenever the user changes its contents.
This is useful e.g. for things that need to provide a default value, but cannot find the default at once. Just open the line edit without the best default and 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.
See also edited().
[virtual]
Reimplemented for internal reasons; the API is not affected.
[virtual]
Reimplemented for internal reasons; the API is not affected.
[virtual]
Sets the line edit to draw itself inside a two-pixel frame if enable is TRUE, and to draw itself without any frame if enable is FALSE.
The default is TRUE.
See also frame().
[virtual]
Set the maximum length of the text in the editor. If the text is too long, it is chopped off at the limit. Any marked text will be unmarked. The cursor position is set to 0 and the first part of the string is shown.
See also maxLength().
[virtual]
Reimplemented for internal reasons; the API is not affected.
Enables or disables read-only mode, where the user can cut-and-paste or drag-and-drop the text, but cannot edit it. They never see a cursor in this case.
See also setEnabled() and isReadOnly().
[virtual]
Sets the marked area of this line edit to start at start and be length characters long.
[virtual slot]
Sets the line edit text to text, clears the selection and moves the cursor to the end of the line.
If necessary the text is truncated to maxLength().
See also text().
Examples: xform/xform.cpp
[virtual]
Sets this line edit to accept input only as accepted by v, allowing arbitrary constraints on the text which the user can edit.
If v == 0, remove the current input validator. The default is no input validator (ie. any input is accepted up to maxLength()).
See also validator() and QValidator.
[virtual]
Returns a recommended size for the widget.
The width returned is enough for a few characters, typically 15 to 20.
Reimplemented from QWidget.
[virtual]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
Returns the text in the line.
See also setText().
[signal]
This signal is emitted every time the text changes. The argument is the new text.
Validates and perhaps sets this line edit to contain newText with the cursor at position newPos, with marked text from newMarkAnchor to newMarkDrag. Returns TRUE if it changes the line edit and FALSE if it doesn't.
Linebreaks in newText are converted to spaces, and it is truncated to maxLength() before testing its validity.
Repaints and emits textChanged() if appropriate.
Returns a pointer to the current input validator, or 0 if no validator has been set.
See also setValidator().
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
Copyright © 2000 Trolltech | Trademarks | Qt version 2.2.1
|