QLineEdit Class Reference


QLineEdit is a simple line editor, suitable e.g. for asking the user for his name. (details) (complete member list)

#include <qlined.h>

Inherits QWidget.

Public Members

Public Slots

Signals

Protected Members


Detailed Description

QLineEdit is a simple line editor, suitable e.g. for asking the user for his name.

The default key bindings are described in keyPressEvent(); they cannot be customized except by inheriting the class. When the user clicks on the text, the cursor will be moved to the point being clicked at.

To do:


Member Function Documentation

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

Creates a new line editor inside widget parent, named name. Both parent and name are as usual - in fact both are passed straight to the QWidget constructor.

This constructor sets the cursor position to the start of the line, the maximum length to 32767 characters, and the current contents of the line to "".

QLineEdit::~QLineEdit ()

Cleans up when a QLineEdit dies.

bool QLineEdit::backspace ()

If it can delete leftwards, does that and returns TRUE, othewise it returns FALSE

bool QLineEdit::cursorLeft ()

Moves the cursor leftwards one character, restarts the blink timer, and returns TRUE.

Returns FALSE if the cursor is already at the leftmost position.

bool QLineEdit::cursorRight ()

Moves the cursor rightwards one character, restarts the blink timer, and returns TRUE.

Returns FALSE if the cursor is already at the rightmost position.

bool QLineEdit::end ()

Moves the text cursor to the right end of the line, restarts the blink timer, and returns TRUE. Or, if the cursor is already there, returns FALSE.

void QLineEdit::focusInEvent (QFocusEvent *)

This event occurs whenever the mouse enters the line editor. It starts the blink timer, etc.

void QLineEdit::focusOutEvent (QFocusEvent *)

This event occurs whenever the mouse leaves the line editor. It stops the editor's cursor from blinking, etc.

bool QLineEdit::home ()

Moves the text cursor to the left end of the line, restarts the blink timer, and returns TRUE. Or, if the cursor is already there, returns FALSE.

void QLineEdit::keyPressEvent (QKeyEvent *e)

This function contains the guts of the line editor.

Here are the default key bindings:

Left Arrow
Move the cursor one character leftwards
Right Arrow
Move the cursor one character rightwards
Backspace
Delete the character to the left of the cursor
Home
Move the cursor to the beginning of the line
End
Move the cursor to the end of the line
Delete
Delete the character to the right of the cursor
Control-A
Move the cursor to the beginning of the line
Control-B
Move the cursor one character leftwards
Control-D
Delete the character to the right of the cursor
Control-E
Move the cursor to the end of the line
Control-F
Move the cursor one character rightwards
Control-H
Delete the character to the left of the cursor

Comments solicited

All other keys insert themselves into the line.

To do:

int QLineEdit::maxLength () const

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

void QLineEdit::mousePressEvent (QMouseEvent *e)

Handles mouse clicks.

At present, this event handler only moves the text cursor to the mouse position and accepts the focus.

To do:

void QLineEdit::paint (bool frame)

Repaints the line editor as needed. If the line editor is in focus, the line is painted using a pixmap buffer. If not, a faster but flickering drawing method is used.

void QLineEdit::paintEvent (QPaintEvent *)

This event occurs whenever the widget needs repainting.

void QLineEdit::paintText (QPainter *p, const QSize &sz, bool frame = FALSE)

Paints the line editor quickly, efficently and without the slightest thought about flicker or other bourgeois problems

void QLineEdit::pixmapPaint ()

Paints the line editor slowly, prettily and without flicker

bool QLineEdit::remove ()

If it can delete rightwards, does that and returns TRUE, othewise it returns FALSE

void QLineEdit::resizeEvent (QResizeEvent *e)

This event occurs whenever the widget is resized; if necessary it will move the cursor, scroll the text and repaint.

void QLineEdit::setMaxLength (int m)

Set the maximum length of the text in the editor. If the text is currently too long, it is chopped off at the limit.

void QLineEdit::setText (const char *s)

Replaces the text currently in the line with s. If necessary the string is truncated to fit maxLength().

char * QLineEdit::text () const

Returns a pointer to the text currently in the line.

If you need to store the text, you should make a copy of it. This can convienently be done with a QString object:

  QString s = linEd->text();  // makes a copy and stores it in s

void QLineEdit::textChanged (char *)

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

void QLineEdit::timerEvent (QTimerEvent *)

This event is used to implement the blinking text cursor.


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

It was generated from the following files:


Generated at 04:27, 1995/05/20 by the webmaster at Troll Tech