ScrollableLineEdit Class Reference

The ScrollableLineEdit widget is a one-line text editor. More...

#include <ScrollableLineEdit.h>

List of all members.

Public Types

enum  EchoMode { Normal, NoEcho, Password }

Public Slots

virtual void setText (const QString &)
void selectAll ()
void deselect ()
void clearValidator ()
void insert (const QString &)
void clear ()
void scrollLeft ()
void scrollRight ()

Signals

void textChanged (const QString &)
void returnPressed ()

Public Member Functions

 ScrollableLineEdit (QWidget *parent, const char *name=0)
 ScrollableLineEdit (const QString &, QWidget *parent, const char *name=0)
 ~ScrollableLineEdit ()
QString text () const
QString displayText () const
int maxLength () const
virtual void setMaxLength (int)
virtual void setFrame (bool)
bool frame () const
virtual void setEchoMode (EchoMode)
EchoMode echoMode () const
void setReadOnly (bool)
bool isReadOnly () const
virtual void setValidator (const QValidator *)
const QValidator * validator () const
QSize sizeHint () const
QSize minimumSizeHint () const
QSizePolicy sizePolicy () const
virtual void setEnabled (bool)
virtual void setFont (const QFont &)
virtual void setPalette (const QPalette &)
virtual void setSelection (int, int)
virtual void setCursorPosition (int)
int cursorPosition () const
bool validateAndSet (const QString &, int, int, int)
void cut ()
void copy () const
void paste ()
void setAlignment (int flag)
int alignment () const
void cursorLeft (bool mark, int steps=1)
void cursorRight (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)
void setEdited (bool)
bool edited () const
bool hasMarkedText () const
QString markedText () const

Protected Member Functions

bool event (QEvent *)
void mousePressEvent (QMouseEvent *)
void mouseMoveEvent (QMouseEvent *)
void mouseReleaseEvent (QMouseEvent *)
void mouseDoubleClickEvent (QMouseEvent *)
void keyPressEvent (QKeyEvent *)
void focusInEvent (QFocusEvent *)
void focusOutEvent (QFocusEvent *)
void paintEvent (QPaintEvent *)
void resizeEvent (QResizeEvent *)
void leaveEvent (QEvent *)
void dragEnterEvent (QDragEnterEvent *)
void dropEvent (QDropEvent *)
void repaintArea (int, int)
void keyReleaseEvent (QKeyEvent *)

Properties

QString text
int maxLength
bool frame
EchoMode echoMode
QString displayText
int cursorPosition
Alignment alignment
bool edited
bool hasMarkedText
QString markedText


Detailed Description

The ScrollableLineEdit 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 & 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 ScrollableLineEdit 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.

qlined-m.png>
qlined-w.png>

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

Definition at line 64 of file ScrollableLineEdit.h.


Member Enumeration Documentation

This enum type describes how ScrollableLineEdit displays its contents. The defined values 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.

See also:
setEchoMode() echoMode() QMultiLineEdit::EchoMode
Enumerator:
Normal 
NoEcho 
Password 

Definition at line 94 of file ScrollableLineEdit.h.


Constructor & Destructor Documentation

ScrollableLineEdit::ScrollableLineEdit ( 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:
setText(), setMaxLength()

Definition at line 191 of file ScrollableLineEdit.cpp.

ScrollableLineEdit::ScrollableLineEdit ( 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(), setMaxLength()

Definition at line 209 of file ScrollableLineEdit.cpp.

ScrollableLineEdit::~ScrollableLineEdit (  ) 

Destructs the line edit.

Definition at line 222 of file ScrollableLineEdit.cpp.


Member Function Documentation

QString ScrollableLineEdit::text (  )  const

QString ScrollableLineEdit::displayText (  )  const

int ScrollableLineEdit::maxLength (  )  const

void ScrollableLineEdit::setMaxLength ( int  m  )  [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().

Definition at line 410 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::setFrame ( bool  enable  )  [virtual]

Sets the line edit to draw itself inside a frame if enable is TRUE, and to draw itself without any frame if enable is FALSE.

The default is TRUE.

See also:
frame()

Definition at line 1350 of file ScrollableLineEdit.cpp.

bool ScrollableLineEdit::frame (  )  const

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

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

Definition at line 1399 of file ScrollableLineEdit.cpp.

EchoMode ScrollableLineEdit::echoMode (  )  const

void ScrollableLineEdit::setReadOnly ( bool  enable  ) 

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(), isReadOnly()

Definition at line 1429 of file ScrollableLineEdit.cpp.

bool ScrollableLineEdit::isReadOnly (  )  const

Returns whether the line-edit is read-only.

See also:
setReadOnly()

Definition at line 1438 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::setValidator ( const QValidator *  v  )  [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() QValidator

Definition at line 1511 of file ScrollableLineEdit.cpp.

const QValidator * ScrollableLineEdit::validator (  )  const

Returns a pointer to the current input validator, or 0 if no validator has been set.

See also:
setValidator()

Definition at line 1523 of file ScrollableLineEdit.cpp.

QSize ScrollableLineEdit::sizeHint (  )  const

Returns a recommended size for the widget.

The width returned is enough for a few characters, typically 15 to 20.

Definition at line 1450 of file ScrollableLineEdit.cpp.

QSize ScrollableLineEdit::minimumSizeHint (  )  const

Returns a minimum size for the line edit.

The width returned is enough for at least one character.

Definition at line 1474 of file ScrollableLineEdit.cpp.

QSizePolicy ScrollableLineEdit::sizePolicy (  )  const

Definition at line 1494 of file ScrollableLineEdit.cpp.

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

Definition at line 1747 of file ScrollableLineEdit.cpp.

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

Definition at line 1756 of file ScrollableLineEdit.cpp.

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

Definition at line 1819 of file ScrollableLineEdit.cpp.

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

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

Definition at line 1777 of file ScrollableLineEdit.cpp.

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

Sets the cursor position for this line edit to newPos and repaints accordingly.

See also:
cursorPosition()

Definition at line 1793 of file ScrollableLineEdit.cpp.

int ScrollableLineEdit::cursorPosition (  )  const

bool ScrollableLineEdit::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.

Definition at line 1615 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::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() paste()

Definition at line 1266 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::copy (  )  const

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

See also:
cut() paste()

Definition at line 1230 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::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() cut()

Definition at line 1251 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::setAlignment ( int  flag  ) 

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

Definition at line 1282 of file ScrollableLineEdit.cpp.

int ScrollableLineEdit::alignment (  )  const

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

Moves the cursor leftwards one or more characters.

See also:
cursorRight()

Definition at line 1080 of file ScrollableLineEdit.cpp.

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

Moves the cursor rightwards one or more characters.

See also:
cursorLeft()

Definition at line 1090 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::cursorWordForward ( bool  mark  ) 

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

See also:
cursorWordBackward()

Definition at line 1864 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::cursorWordBackward ( bool  mark  ) 

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

See also:
cursorWordForward()

Definition at line 1880 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::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()

Definition at line 1114 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::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()

Definition at line 1137 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::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()

Definition at line 1163 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::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()

Definition at line 1175 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::setEdited ( bool  on  ) 

Sets the edited flag of this line edit to on. The edited flag is never read by ScrollableLineEdit, 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()

Definition at line 1839 of file ScrollableLineEdit.cpp.

bool ScrollableLineEdit::edited (  )  const

bool ScrollableLineEdit::hasMarkedText (  )  const

QString ScrollableLineEdit::markedText (  )  const

void ScrollableLineEdit::setText ( const QString &  text  )  [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()

Definition at line 276 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::selectAll (  )  [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.

Definition at line 311 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::deselect (  )  [slot]

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

Definition at line 324 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::clearValidator (  )  [slot]

This slot is equivalent to setValidator( 0 ).

Definition at line 1531 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::insert ( const QString &  newText  )  [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.

Definition at line 1676 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::clear (  )  [slot]

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

Definition at line 1768 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::scrollLeft (  )  [slot]

Definition at line 2047 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::scrollRight (  )  [slot]

Definition at line 2052 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::textChanged ( const QString &  t0  )  [signal]

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

Definition at line 328 of file moc_ScrollableLineEdit.cpp.

void ScrollableLineEdit::returnPressed (  )  [signal]

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

Definition at line 334 of file moc_ScrollableLineEdit.cpp.

bool ScrollableLineEdit::event ( QEvent *  e  )  [protected]

Definition at line 816 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::mousePressEvent ( QMouseEvent *  e  )  [protected]

Definition at line 867 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::mouseMoveEvent ( QMouseEvent *  e  )  [protected]

Definition at line 970 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::mouseReleaseEvent ( QMouseEvent *  e  )  [protected]

Definition at line 1011 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::mouseDoubleClickEvent ( QMouseEvent *   )  [protected]

Definition at line 1065 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::keyPressEvent ( QKeyEvent *  e  )  [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 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.
  • Shift - Left Arrow Move and mark text one character leftwards.
  • Shift - Right Arrow Move and mark text one character rightwards.
  • Control-A Move the cursor to the beginning of the line.
  • Control-B Move the cursor one character leftwards.
  • Control-C Copy the marked text to the clipboard.
  • 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.
  • Control-K Delete to end of line
  • Control-V Paste the clipboard text into line edit.
  • Control-X Move the marked text to the clipboard.
  • Control-Z Undo the last operation.
  • Control-Y Redo the last undone operation.
In addition, the following key bindings are used on Windows:
  • Shift - Delete Cut the marked text, copy to clipboard
  • Shift - Insert Paste the clipboard text into line edit
  • Control - Insert Copy the marked text to the clipboard

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

Definition at line 470 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::focusInEvent ( QFocusEvent *  e  )  [protected]

Definition at line 662 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::focusOutEvent ( QFocusEvent *  e  )  [protected]

Definition at line 677 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::paintEvent ( QPaintEvent *  e  )  [protected]

Definition at line 699 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::resizeEvent ( QResizeEvent *   )  [protected]

Definition at line 805 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::leaveEvent ( QEvent *   )  [protected]

Definition at line 691 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::dragEnterEvent ( QDragEnterEvent *  e  )  [protected]

Definition at line 1540 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::dropEvent ( QDropEvent *  e  )  [protected]

Definition at line 1549 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::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.

Definition at line 1709 of file ScrollableLineEdit.cpp.

void ScrollableLineEdit::keyReleaseEvent ( QKeyEvent *  e  )  [protected]

Definition at line 2057 of file ScrollableLineEdit.cpp.


Property Documentation

QString ScrollableLineEdit::text [read, write]

Returns the text in the line.

See also:
setText()

Definition at line 68 of file ScrollableLineEdit.h.

int ScrollableLineEdit::maxLength [read, write]

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

See also:
setMaxLength()

Definition at line 69 of file ScrollableLineEdit.h.

bool ScrollableLineEdit::frame [read, write]

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

Definition at line 70 of file ScrollableLineEdit.h.

ScrollableLineEdit::EchoMode ScrollableLineEdit::echoMode [read, write]

Returns the echo mode of the line edit.

See also:
setEchoMode() EchoMode

Definition at line 71 of file ScrollableLineEdit.h.

QString ScrollableLineEdit::displayText [read]

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

Definition at line 72 of file ScrollableLineEdit.h.

int ScrollableLineEdit::cursorPosition [read, write]

Returns the current cursor position for this line edit.

See also:
setCursorPosition()

Definition at line 73 of file ScrollableLineEdit.h.

int ScrollableLineEdit::alignment [read, write]

Returns the alignment of the line edit. Possible Values are Qt::AlignLeft, Qt::AlignRight and Qt::Align(H)Center.

See also:
setAlignment(), Qt::AlignmentFlags

Definition at line 74 of file ScrollableLineEdit.h.

bool ScrollableLineEdit::edited [read, write]

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

Definition at line 75 of file ScrollableLineEdit.h.

bool ScrollableLineEdit::hasMarkedText [read]

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

See also:
markedText()

Definition at line 76 of file ScrollableLineEdit.h.

QString ScrollableLineEdit::markedText [read]

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

Definition at line 77 of file ScrollableLineEdit.h.


The documentation for this class was generated from the following files:

Generated on Sun Mar 1 17:30:48 2009 for toMOTko by  doxygen 1.5.6