QLineEdit Class Reference
The QLineEdit widget is a one-line text editor.
More...
#include <qlineedit.h>
Inherits QFrame.
List of all member functions.
Public Members
QLineEdit ( QWidget * parent, const char * name = 0 )
QLineEdit ( const QString & contents, QWidget * parent, const char * name = 0 )
enum
EchoMode { Normal, NoEcho, Password }
bool
validateAndSet ( const QString & newText, int newPos, int newMarkAnchor, int newMarkDrag )
void cursorLeft ( bool mark, int steps = 1 ) (obsolete)
void cursorRight ( bool mark, int steps = 1 ) (obsolete)
bool hasSelectedText () const
QString selectedText () const
bool dragEnabled () const
Public Slots
Signals
Properties
QString
text - the text in the line
int
maxLength - the maximum permitted length of the text in the editor
bool
frame - whether the line edit draws itself with a frame
EchoMode
echoMode - the echo mode of the line edit
Alignment
alignment - the alignment of the line edit
bool
edited - the edited flag of the line edit
bool
hasMarkedText - whether part of the text has been selected by the user (e.g.,
by clicking and dragging)
QString
markedText - the text selected by the user (e.g., by clicking and
dragging), or QString::null if no text is selected
bool dragEnabled
bool
readOnly - whether the line edit is read only
Protected Members
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 field can be constrained to a maxLength(), or the
value can be arbitrarily constrained by setting a validator().
A closely related class is QTextEdit which allows multi-line, rich-text
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 QTextEdit, QLabel, QComboBox, GUI Design Handbook: Field, Entry, and GUI Design Handbook: Field, Required..
Member Type Documentation
QLineEdit::EchoMode
This enum type describes how QLineEdit displays its
contents. The defined values are:
- QLineEdit::Normal - displays characters as they are entered. This is
the default.
- QLineEdit::NoEcho - does not display anything. This may be appropriate
for passwords where even the length of the password should
be kept secret.
- QLineEdit::Password - displays asterisks instead of the characters
actually entered.
See also echoMode and echoMode.
Member Function Documentation
QLineEdit::QLineEdit ( QWidget * parent, const char * name = 0 )
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 text and maxLength.
QLineEdit::QLineEdit ( const QString & contents, QWidget * parent, const char * name = 0 )
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 maxLength.
QLineEdit::~QLineEdit ()
Destroys the line edit.
int QLineEdit::alignment () const
Returns the alignment of the line edit. See the "alignment" property for details.
void QLineEdit::backspace ()
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().
void QLineEdit::clear () [virtual slot]
Syntactic sugar for setText( "" ), provided to match no-argument
signals.
void QLineEdit::clearValidator () [virtual slot]
This slot is equivalent to setValidator( 0 ).
void QLineEdit::copy () const [virtual slot]
Copies the marked text to the clipboard, if there is any and
if echoMode() is Normal.
See also cut() and paste().
QPopupMenu * QLineEdit::createPopupMenu () [virtual protected]
This function is called to create the popup menu which is shown
when the user clicks on the lineedit with the right mouse button. If
you want to create a custom popup menu, reimplement this function
and return the created popup menu. The ownership is transferred to
the caller.
void QLineEdit::cursorBackward ( bool mark, int steps = 1 )
Moves the cursor back one or more characters.
See also cursorForward().
void QLineEdit::cursorForward ( bool mark, int steps = 1 )
Moves the cursor forward one or more characters.
See also cursorBackward().
void QLineEdit::cursorLeft ( bool mark, int steps = 1 )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
For compatibilty with older applications only. Use cursorBackward
instead.
See also cursorBackward().
int QLineEdit::cursorPosition () const
Returns the current cursor position for this line edit. See the "cursorPosition" property for details.
void QLineEdit::cursorRight ( bool mark, int steps = 1 )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Use cursorForward instead.
See also cursorForward().
void QLineEdit::cursorWordBackward ( bool mark )
Moves the cursor one word backward. If mark is TRUE, the text
is marked.
See also cursorWordForward().
void QLineEdit::cursorWordForward ( bool mark )
Moves the cursor one word forward. If mark is TRUE, the text
is marked.
See also cursorWordBackward().
void QLineEdit::cut () [virtual slot]
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.
See also copy() and paste().
void QLineEdit::del ()
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().
void QLineEdit::deselect () [virtual slot]
Deselects all text (i.e., removes marking) and leaves the cursor at the
current position.
See also setSelection() and selectAll().
QString QLineEdit::displayText () const
Returns the text that is displayed. See the "displayText" property for details.
EchoMode QLineEdit::echoMode () const
Returns the echo mode of the line edit. See the "echoMode" property for details.
bool QLineEdit::edited () const
Returns the edited flag of the line edit. See the "edited" property for details.
void QLineEdit::end ( bool mark )
Moves the text cursor to the end of the line. If mark is TRUE, text
is marked towards the last position; if not, any marked text is unmarked
if the cursor is moved. See also home().
bool QLineEdit::frame () const
Returns TRUE if the line edit draws itself with a frame; otherwise returns FALSE. See the "frame" property for details.
bool QLineEdit::getSelection ( int * start, int * end )
This function sets start to the position in the text where the
selection starts and end to the selection end and returns TRUE,
if there is a selection. Else it returns FALSE:
bool QLineEdit::hasMarkedText () const
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.
void QLineEdit::home ( bool mark )
Moves the text cursor to the beginning of the line. If mark is TRUE,
text is marked towards the first position; if not, any marked text is
unmarked if the cursor is moved. See also end().
void QLineEdit::insert ( const QString & newText ) [virtual slot]
Removes any selected text, inserts newText,
and validates the result. If it is valid, it sets it as the new contents
of the line edit.
bool QLineEdit::isReadOnly () const
Returns TRUE if the line edit is read only; otherwise returns FALSE. See the "readOnly" property for details.
void QLineEdit::keyPressEvent ( QKeyEvent * e ) [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:
- 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.
- 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 marks text one character to the left.
- Shift - Right Arrow - moves and marks text one character to the right.
- Control-A - moves the cursor to the beginning of the line.
- Control-B - moves the cursor one character to the left.
- Control-C - copies the marked text to the clipboard.
- Control-D - deletes the character to the right of the cursor.
- Control-E - moves the cursor to the end of the line.
- Control-F - moves the cursor one character to the right.
- Control-H - deletes the character to the left of the cursor.
- Control-K - deletes to the end of the line.
- Control-V - pastes the clipboard text into line edit.
- Control-X - moves the marked text to the clipboard.
- Control-Z - undoes the last operation.
- Control-Y - redoes the last undone operation.
In addition, the following key bindings are used on Windows:
- Shift - Delete - cuts the marked text, copies to clipboard.
- Shift - Insert - pastes the clipboard text into line edit.
- Control - Insert - copies the marked text to the clipboard.
All other keys with valid ASCII codes insert themselves into the line.
Reimplemented from QWidget.
QString QLineEdit::markedText () const
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.
int QLineEdit::maxLength () const
Returns the maximum permitted length of the text in the editor. See the "maxLength" property for details.
QSize QLineEdit::minimumSizeHint () const [virtual]
Returns a minimum size for the line edit.
The width returned is enough for one character at least.
Reimplemented from QWidget.
void QLineEdit::paste () [virtual slot]
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.
See also copy() and cut().
void QLineEdit::redo () [virtual slot]
Redoes the last operation
void QLineEdit::repaintArea ( int from, int to ) [protected]
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Repaints all characters from from to to. If cursorPos is
between from and to, ensures that cursorPos is visible.
void QLineEdit::returnPressed () [signal]
This signal is emitted when the Return or Enter key is pressed.
Example: popup/popup.cpp.
void QLineEdit::selectAll () [virtual 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
because if the user types before clicking on the widget, the
selected text will be erased.
See also setSelection() and deselect().
void QLineEdit::setCursorPosition ( int ) [virtual slot]
Sets the current cursor position for this line edit. See the "cursorPosition" property for details.
void QLineEdit::setEchoMode ( EchoMode ) [virtual slot]
Sets the echo mode of the line edit. See the "echoMode" property for details.
void QLineEdit::setEdited ( bool )
Sets the edited flag of the line edit. See the "edited" property for details.
void QLineEdit::setFrame ( bool ) [virtual slot]
Sets whether the line edit draws itself with a frame. See the "frame" property for details.
void QLineEdit::setMaxLength ( int ) [virtual slot]
Sets the maximum permitted length of the text in the editor. See the "maxLength" property for details.
void QLineEdit::setReadOnly ( bool ) [virtual slot]
Sets whether the line edit is read only. See the "readOnly" property for details.
void QLineEdit::setSelection ( int start, int length ) [virtual slot]
Sets the marked area of this line edit to start at start and
be length characters long.
See also deselect() and selectAll().
void QLineEdit::setText ( const QString & ) [virtual slot]
Sets the text in the line. See the "text" property for details.
void QLineEdit::setValidator ( const QValidator * v ) [virtual slot]
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, 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.
QSize QLineEdit::sizeHint () const [virtual]
Returns a recommended size for the widget.
The width returned is enough for a few characters, typically 15 to 20
pixels.
Example: addressbook/centralwidget.cpp.
Reimplemented from QFrame.
QString QLineEdit::text () const
Returns the text in the line. See the "text" property for details.
void QLineEdit::textChanged ( const QString & ) [signal]
This signal is emitted every time the text changes.
The argument is the new text.
Examples: wizard/wizard.cpp and xform/xform.cpp.
void QLineEdit::undo () [virtual slot]
Undoes the last operation
bool QLineEdit::validateAndSet ( const QString & newText, int newPos, int newMarkAnchor, int newMarkDrag )
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.
const QValidator * QLineEdit::validator () const
Returns a pointer to the current input validator, or 0 if no
validator has been set.
See also setValidator().
Example: wizard/wizard.cpp.
Property Documentation
Alignment alignment
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.
Set this property's value with setAlignment() and get this property's value with alignment().
See also Qt::AlignmentFlags.
int cursorPosition
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 text that is displayed.
This is normally the same as text(), but can be a string
like "*****" if EchoMode is Password or "" if it is NoEcho.
Get this property's value with displayText().
See also echoMode, text and EchoMode.
This property holds the echo mode of the line edit.
The initial setting is Normal, but QLineEdit also supports NoEcho
and Password.
The widget's display and the ability to copy or drag the text is
affected by this setting.
Set this property's value with setEchoMode() and get this property's value with echoMode().
See also EchoMode and displayText.
bool edited
This property holds the edited flag of the line edit.
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 edits
contents.
This is useful 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; 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().
bool frame
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().
bool hasMarkedText
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 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.
int maxLength
This property holds the maximum permitted 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.
Set this property's value with setMaxLength() and get this property's value with maxLength().
bool readOnly
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.
Set this property's value with setReadOnly() and get this property's value with isReadOnly().
See also enabled.
This property holds the text in the line.
Setting this property clears the selection and moves the cursor to the end
of the line.
The text is truncated to maxLength() length.
Set this property's value with setText() and get this property's value with text().
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit,
copyright © 1995-2001
Trolltech, all rights reserved.
Copyright © 2001 Trolltech | Trademarks
| Qt version 3.0.0-beta1-beta1
|