QLineEdit

Section: Misc. Reference Manual Pages (3qt)
Updated: 2 February 2007
Index Return to Main Contents
 

NAME

QLineEdit - One-line text editor  

SYNOPSIS

#include <qlineedit.h>

Inherits QFrame.

 

Public Members


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

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

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

~QLineEdit ()

QString text () const

QString displayText () const

int maxLength () const

bool frame () const

enum EchoMode { Normal, NoEcho, Password }

EchoMode echoMode () const

bool isReadOnly () const

const QValidator * validator () const

virtual QSize sizeHint () const

virtual QSize minimumSizeHint () const

int cursorPosition () const

bool validateAndSet ( const QString & newText, int newPos, int newMarkAnchor, int newMarkDrag ) (obsolete)

int alignment () const

void cursorLeft ( bool mark, int steps = 1 ) (obsolete)

void cursorRight ( bool mark, int steps = 1 ) (obsolete)

void cursorForward ( bool mark, int steps = 1 )

void cursorBackward ( bool mark, int steps = 1 )

void cursorWordForward ( bool mark )

void cursorWordBackward ( bool mark )

void backspace ()

void del ()

void home ( bool mark )

void end ( bool mark )

bool isModified () const

void clearModified ()

bool edited () const (obsolete)

void setEdited ( bool ) (obsolete)

bool hasSelectedText () const

QString selectedText () const

int selectionStart () const

bool isUndoAvailable () const

bool isRedoAvailable () const

bool hasMarkedText () const (obsolete)

QString markedText () const (obsolete)

bool dragEnabled () const

QString inputMask () const

void setInputMask ( const QString & inputMask )

bool hasAcceptableInput () const

int characterAt ( int xpos, QChar * chr ) const (obsolete)

bool getSelection ( int * start, int * end ) (obsolete)
 

Public Slots


virtual void setText ( const QString & )

virtual void selectAll ()

virtual void deselect ()

virtual void clearValidator ()

virtual void insert ( const QString & newText )

virtual void clear ()

virtual void undo ()

virtual void redo ()

virtual void setMaxLength ( int )

virtual void setFrame ( bool )

virtual void setEchoMode ( EchoMode )

virtual void setReadOnly ( bool )

virtual void setValidator ( const QValidator * v )

virtual void setSelection ( int start, int length )

virtual void setCursorPosition ( int )

virtual void setAlignment ( int flag )

virtual void cut ()

virtual void copy () const

virtual void paste ()

virtual void setDragEnabled ( bool b )
 

Signals


void textChanged ( const QString & )

void returnPressed ()

void lostFocus ()

void selectionChanged ()
 

Properties


bool acceptableInput - whether the input satisfies the inputMask and the validator (read only)

Alignment alignment - the alignment of the line edit

int cursorPosition - the current cursor position for this line edit

QString displayText - the displayed text (read only)

bool dragEnabled - whether the lineedit starts a drag if the user presses and moves the mouse on some selected text

EchoMode echoMode - the line edit's echo mode

bool edited - whether the line edit has been edited. Use modified instead (obsolete)

bool frame - whether the line edit draws itself with a frame

bool hasMarkedText - whether part of the text has been selected by the user. Use hasSelectedText instead (read only) (obsolete)

bool hasSelectedText - whether there is any text selected (read only)

QString inputMask - the validation input mask

QString markedText - the text selected by the user. Use selectedText instead (read only) (obsolete)

int maxLength - the maximum permitted length of the text

bool modified - whether the line edit's contents has been modified by the user (read only)

bool readOnly - whether the line edit is read only

bool redoAvailable - whether redo is available (read only)

QString selectedText - the selected text (read only)

QString text - the line edit's text

bool undoAvailable - whether undo is available (read only)
 

Protected Members


virtual void keyPressEvent ( QKeyEvent * e )

virtual QPopupMenu * createPopupMenu ()

void repaintArea ( int from, int to ) (obsolete)
 

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 text can be constrained to maxLength(). The text can be arbitrarily constrained using a validator() or an inputMask(), or both.

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. The line edit also provides a context menu (usually invoke