Wt: Wt::WLineEdit Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Member Functions
Wt::WLineEdit Class Reference

A widget that provides a single line edit. More...

`#include <Wt/WLineEdit>`

Inheritance diagram for Wt::WLineEdit:
[legend]

List of all members.

## Public Types
enum | EchoMode { Normal, Password }
| Enumeration that describes how the contents is displayed. More...
## Public Member Functions
| WLineEdit (WContainerWidget *parent=0)
| Creates a line edit with empty content and optional parent.
| WLineEdit (const WString &content, WContainerWidget *parent=0)
| Creates a line edit with given content and optional parent.
void | setTextSize (int chars)
| Specifies the width of the line edit in number of characters.
int | textSize () const
| Returns the current width of the line edit in number of characters.
virtual void | setText (const WString &text)
| Sets the content of the line edit.
const WString & | text () const
| Returns the current content.
void | setMaxLength (int length)
| Specifies the maximum length of text that can be entered.
int | maxLength () const
| Returns the maximum length of text that can be entered.
void | setEchoMode (EchoMode echoMode)
| Sets the echo mode.
EchoMode | echoMode () const
| Returns the echo mode.
int | selectionStart () const
| Returns the current selection start.
WString | selectedText () const
| Returns the currently selected text.
bool | hasSelectedText () const
| Returns whether there is selected text.
int | cursorPosition () const
| Returns the current cursor position.
virtual WString | valueText () const
| Returns the current value.
virtual void | setValueText (const WString &value)
| Sets the current value.
## Protected Member Functions
virtual int | boxPadding (Orientation orientation) const
| Returns the widget's built-in padding.
virtual int | boxBorder (Orientation orientation) const
| Returns the widget's built-in border width.

## Detailed Description

A widget that provides a single line edit.

To act upon text changes, connect a slot to the changed() signal. This signal is emitted when the user changed the content, and subsequently removes the focus from the line edit.

To act upon editing, connect a slot to the keyWentUp() signal because the keyPressed() signal is fired before the line edit has interpreted the keypress to change its text.

At all times, the current content may be accessed with the text() method.

You may specify a maximum length for the input using setMaxLength(). If you wish to provide more detailed input validation, you may set a validator using the setValidator(WValidator *) method. Validators provide, in general, both client-side validation (as visual feed-back only) and server-side validation when calling validate().

Usage example:

     Wt::WContainerWidget *w = new Wt::WContainerWidget();
     Wt::WLabel *label = new Wt::WLabel("Age:", w);
     Wt::WLineEdit *edit = new Wt::WLineEdit("13", w);
     edit->setValidator(new Wt::WIntValidator(0, 200));
     label->setBuddy(edit);

The widget corresponds to the HTML `<input type="text">` or `<input type="password">` tag.

WLineEdit is an inline widget.

### CSS

The emptyText style can be configured via .Wt-edit-emptyText, other styling can be done using inline or external CSS as appropriate.

See also:
  WTextArea

## Member Enumeration Documentation

enum Wt::WLineEdit::EchoMode

Enumeration that describes how the contents is displayed.

See also:
  setEchoMode(EchoMode)

Enumerator:

  Normal | Characters are shown.
  Password | Hide the contents as for a password.

## Member Function Documentation

int Wt::WLineEdit::boxBorder | ( | Orientation | orientation | ) | const`[protected, virtual]`

Returns the widget's built-in border width.

This is used by the layout managers to correct for a built-in border which interferes with setting a widget's width (or height) to 100%.

A layout manager needs to set the width to 100% only for form widgets (WTextArea, WLineEdit, WComboBox, etc...). Therefore, only for those widgets this needs to return the border width (the default implementation returns 0).

For form widgets, the border width depends on the specific browser/platform combination, unless an explicit border is set for the widget.

When setting an explicit border for the widget using a style class, you will want to reimplement this method to return this border width, in case you want to set the widget inside a layout manager.

See also:
  boxPadding()

Reimplemented from Wt::WWidget.

int Wt::WLineEdit::boxPadding | ( | Orientation | orientation | ) | const`[protected, virtual]`

Returns the widget's built-in padding.

This is used by the layout managers to correct for a built-in padding which interferes with setting a widget's width (or height) to 100%.

A layout manager needs to set the width to 100% only for form widgets (WTextArea, WLineEdit, WComboBox, etc...). Therefore, only for those widgets this needs to return the padding (the default implementation returns 0).

For form widgets, the padding depends on the specific browser/platform combination, unless an explicit padding is set for the widget.

When setting an explicit padding for the widget using a style class, you will want to reimplement this method to return this padding in case you want to set the widget inside a layout manager.

See also:
  boxBorder()

Reimplemented from Wt::WWidget.

Reimplemented in Wt::WAbstractSpinBox.

int Wt::WLineEdit::cursorPosition | ( |  | ) | const

Returns the current cursor position.

Returns -1 if the widget does not have the focus.

EchoMode Wt::WLineEdit::echoMode | ( |  | ) | const

Returns the echo mode.

See also:
  setEchoMode(EchoMode)

bool Wt::WLineEdit::hasSelectedText | ( |  | ) | const

Returns whether there is selected text.

See also:
  selectedtext()

int Wt::WLineEdit::maxLength | ( |  | ) | const

Returns the maximum length of text that can be entered.

See also:
  setMaxLength(int)

WString Wt::WLineEdit::selectedText | ( |  | ) | const

Returns the currently selected text.

Returns an empty string if there is currently no selected text.

See also:
  hasSelectedText()

int Wt::WLineEdit::selectionStart | ( |  | ) | const

Returns the current selection start.

Returns -1 if there is no selected text.

See also:
  hasSelectedText(), selectedText()

void Wt::WLineEdit::setEchoMode | ( | EchoMode | echoMode | ) |

Sets the echo mode.

The default echo mode is Normal.

void Wt::WLineEdit::setMaxLength | ( | int | length | ) |

Specifies the maximum length of text that can be entered.

A value <= 0 indicates that there is no limit.

The default value is -1.

void Wt::WLineEdit::setText | ( | const WString & | text | ) | `[virtual]`

Sets the content of the line edit.

The default value is "".

See also:
  text()

Reimplemented in Wt::WAbstractSpinBox.

void Wt::WLineEdit::setTextSize | ( | int | chars | ) |

Specifies the width of the line edit in number of characters.

This specifies the width of the line edit that is roughly equivalent with `chars` characters. This does not limit the maximum length of a string that may be entered, which may be set using setMaxLength(int).

The default value is 10.

void Wt::WLineEdit::setValueText | ( | const WString & | value | ) | `[virtual]`

Sets the current value.

Calls setText().

Implements Wt::WFormWidget.

const WString& Wt::WLineEdit::text | ( |  | ) | const

Returns the current content.

See also:
  setText()

int Wt::WLineEdit::textSize | ( |  | ) | const

Returns the current width of the line edit in number of characters.

See also:
  setTextSize(int)

WString Wt::WLineEdit::valueText | ( |  | ) | const`[virtual]`

Returns the current value.

Returns text().

Implements Wt::WFormWidget.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator