Qt logo

QLineEdit Class Reference


The QLineEdit widget is a simple line editor for inputting text. More...

#include <qlineedit.h>

Inherits QWidget.

Inherited by QRenameEdit.

List of all member functions.

Public Members

Public Slots

Signals

Protected Members


Detailed Description

The QLineEdit widget is a simple line editor for inputting text.

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 ).

It draws the text using its own color group: colorGroup().text() on colorGroup().base(). The cursor and frame use other colors from same color group, of course.

The default key bindings are described in keyPressEvent(); they cannot be customized except by inheriting the class.

See also: QMultiLineEdit, QLabel, QComboBox, GUI Design Handbook: Field, Entry, and GUI Design Handbook: Field, Required.

Examples: tabdialog/tabdialog.cpp xform/xform.cpp layout/layout.cpp popup/popup.cpp


Member Type Documentation

QLineEdit::EchoMode

This enum type describes the ways in which QLineEdit can display its contents. The currently defined values are:

See also: setEchoMode(), echoMode() and QMultiLineEdit::EchoMode.


Member Function Documentation

QLineEdit::QLineEdit ( QWidget * parent, const char * name=0 )

Constructs a line editor with an empty edit buffer.

The cursor position is set to the start of the line, the maximum buffer size to 32767 characters, and the buffer contents to "".

The parent and name arguments are sent to the QWidget constructor.

QLineEdit::QLineEdit ( const QString & contents, QWidget * parent, const char * name=0 )

Constructs a line editor whose edit buffer starts out as contents.

The cursor position is set to the end of the line and the maximum buffer size to 32767 characters.

The parent and name arguments are sent to the QWidget constructor.

QLineEdit::~QLineEdit ()

Destroys the line editor.

int QLineEdit::alignment () const

Returns the current alignment of the line editor. Possible Values are Qt::AlignLeft, Qt::AlignRight and Qt::AlignCenter.

See also: setAlignment().

void QLineEdit::backspace ()

Deletes the character on the left side 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 () [slot]

Syntax sugar for setText( "" ), provided to match no-argument signals.

void QLineEdit::clearValidator () [slot]

This slot is equivalent to setValidator( 0 ).

void QLineEdit::copy () const

Copies the marked text to the clipboard, if there is any and echoMode() is Normal.

See also: cut() and paste().

void QLineEdit::cursorLeft ( bool mark, int steps = 1 )

Moves the cursor leftwards one or more characters.

See also: cursorRight().

int QLineEdit::cursorPosition () const

Returns the current cursor position for this line edit.

See also: setCursorPosition().

void QLineEdit::cursorRight ( bool mark, int steps = 1 )

Moves the cursor rightwards one or more characters.

See also: cursorLeft().

void QLineEdit::cursorWordBackward ( bool mark )

Moves the cursor one word to the left. If mark is TRUE, the text is marked.

See also: cursorWordForward().

void QLineEdit::cursorWordForward ( bool mark )

Moves the cursor one word to the right. If mark is TRUE, the text is marked.

See also: cursorWordBackward().

void QLineEdit::cut ()

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 () [slot]

Deselects all text (i.e. removes marking) and leaves the cursor at the current position.

QString QLineEdit::displayText () const

Returns the text that's currently 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.

QLineEdit::EchoMode QLineEdit::echoMode() const

Returns the current echo mode of the line edit.

See also: setEchoMode() and EchoMode.

bool QLineEdit::edited () const

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 setEdited( FALSE ), if any). If it returns true, the contents have been edited, or setEdited( TRUE ) has been called.

See also: setEdited().

void QLineEdit::end ( bool mark )

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().

void QLineEdit::focusInEvent ( QFocusEvent * ) [virtual protected]

Handles the cursor blinking.

Reimplemented from QWidget.

void QLineEdit::focusOutEvent ( QFocusEvent * ) [virtual protected]

Handles the cursor blinking and selection copying.

Reimplemented from QWidget.

bool QLineEdit::frame () const

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().

bool QLineEdit::hasMarkedText () const

Returns TRUE if part of the text has been marked by the user (e.g. by clicking and dragging).

void QLineEdit::home ( bool mark )

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().

void QLineEdit::insert ( const QString & newText ) [slot]

Removes any currently selected text, inserts newText, validates the result and if it is valid, sets it as the new contents of the line edit.

void QLineEdit::keyPressEvent ( QKeyEvent * e ) [virtual protected]

The key press event handler converts a key press to some line editor action.

If return or enter is pressed and the current text is valid (or if the validator can make the text valid), the signal returnPressed is emitted.

Here are the default key bindings:

All other keys with valid ASCII codes insert themselves into the line.

Reimplemented from QWidget.

void QLineEdit::leaveEvent ( QEvent * ) [virtual protected]

Handles selection copying.

Reimplemented from QWidget.

QString QLineEdit::markedText () const

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().

int QLineEdit::maxLength () const

Returns the current maximum length of the text in the editor.

See also: setMaxLength().

QSize QLineEdit::minimumSizeHint () const [virtual]

Returns a minimum size for the line edit.

The width returned tends to be enough for one character.

Reimplemented from QWidget.

void QLineEdit::mouseDoubleClickEvent ( QMouseEvent * ) [virtual protected]

Handles mouse double click events for this widget.

Reimplemented from QWidget.

void QLineEdit::mouseMoveEvent ( QMouseEvent * e ) [virtual protected]

Handles mouse move events for the line editor, primarily for marking text.

Reimplemented from QWidget.

void QLineEdit::mousePressEvent ( QMouseEvent * e ) [virtual protected]

Handles mouse press events for this widget.

Reimplemented from QWidget.

void QLineEdit::mouseReleaseEvent ( QMouseEvent * e ) [virtual protected]

Handles mouse release events for this widget.

Reimplemented from QWidget.

void QLineEdit::paintEvent ( QPaintEvent * e ) [virtual protected]

Handles paint events for the line editor.

Reimplemented from QWidget.

void QLineEdit::paste ()

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::repaintArea ( int from, int to ) [protected]

Repaints all characters from from to to. If cursorPos is between from and to, ensures that cursorPos is visible.

void QLineEdit::resizeEvent ( QResizeEvent * ) [virtual protected]

Handles resize events for this widget.

Reimplemented from QWidget.

void QLineEdit::returnPressed () [signal]

This signal is emitted when the return or enter key is pressed.

void QLineEdit::selectAll () [slot]

Selects all text (i.e. marks it) and moves the cursor to the end. Useful when a default value has been inserted. If the user types before clicking on the widget the selected text will be erased.

void QLineEdit::setAlignment ( int flag )

Sets the alignment of the line editor. Possible Values are Qt::AlignLeft, Qt::AlignRight and Qt::AlignCenter.

See also: alignment().

void QLineEdit::setCursorPosition ( int newPos ) [virtual]

Set the cursor position for this line edit to newPos and repaint accordingly.

See also: cursorPosition().

void QLineEdit::setEchoMode ( EchoMode mode ) [virtual]

Sets the echo mode of the line edit widget.

The echo modes available are:

It is always possible to cut and paste any marked text; only the widget's own display is affected.

See also: echoMode(), EchoMode and displayText().

void QLineEdit::setEdited ( bool on )

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().

void QLineEdit::setEnabled ( bool e ) [virtual]

Reimplemented for internal reasons; the API is not affected.

void QLineEdit::setFont ( const QFont & f ) [virtual]

Reimplemented for internal reasons; the API is not affected.

void QLineEdit::setFrame ( bool enable ) [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() and QComboBox.

void QLineEdit::setMaxLength ( int m ) [virtual]

Set the maximum length of the text in the editor. If the text is currently 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().

void QLineEdit::setPalette ( const QPalette & p ) [virtual]

Reimplemented for internal reasons; the API is not affected.

void QLineEdit::setSelection ( int start, int length ) [virtual]

Sets the marked area of this line edit to start at start and be length characters long.

void QLineEdit::setText ( const QString & text ) [virtual slot]

Sets the line editor text to text, clears the selection and moves the cursor to the end of the line.

If necessary the text is truncated to fit maxLength().

See also: text().

Examples: xform/xform.cpp

void QLineEdit::setValidator ( const QValidator * v ) [virtual]

Sets this line edit to accept input only as accepted by v.

If v == 0, remove the currently set input validator. The default is no input validator (ie. any input is accepted up to maxLength()).

See also: validator() and QValidator.

QSize QLineEdit::sizeHint () const [virtual]

Returns a size which fits the contents of the line edit.

The width returned tends to be enough for about 15-20 characters.

Reimplemented from QWidget.

QSizePolicy QLineEdit::sizePolicy () const [virtual]

Specifies that this widget can use more, but is able to survive on less, horizontal space; and is fixed vertically.

Reimplemented from QWidget.

QString QLineEdit::text () const

Returns the text currently in the line.

See also: setText().

void QLineEdit::textChanged ( const QString & ) [signal]

This signal is emitted every time the text has changed. The argument is the new text.

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() if necessary 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.


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.


Copyright © 1999 Troll TechTrademarks
Qt version 2.0.2