Wt: Wt::WLabel Class Reference

Wt 3.3.0

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

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions
Wt::WLabel Class Reference

A label for a form field. More...

`#include <Wt/WLabel>`

Inheritance diagram for Wt::WLabel:
[legend]

List of all members.

## Public Member Functions
| WLabel (WContainerWidget *parent=0)
| Creates a label with empty text and optional parent.
| WLabel (const WString &text, WContainerWidget *parent=0)
| Creates a label with a given text.
| WLabel (WImage *image, WContainerWidget *parent=0)
| Creates a label with an image.
WFormWidget * | buddy () const
| Returns the buddy of this label.
void | setBuddy (WFormWidget *buddy)
| Sets the buddy of this label.
void | setBuddy (Ext::FormField *buddy)
| Sets the buddy of this label.
void | setText (const WString &text)
| Sets the label text.
const WString & | text () const
| Returns the label text.
bool | setTextFormat (TextFormat format)
| Sets the text format.
TextFormat | textFormat () const
| Returns the text format.
void | setImage (WImage *image, Side side=Left)
| Sets the image.
WImage * | image () const
| Returns the image.
void | setWordWrap (bool wordWrap)
| Configures word wrapping.
bool | wordWrap () const
| Returns whether word wrapping is on.
## Protected Member Functions
virtual void | propagateSetEnabled (bool enabled)
| Propagates that a widget was enabled or disabled through children.

## Detailed Description

A label for a form field.

The label may contain an image and/or text. It acts like a proxy for giving focus to a WFormWidget. When both an image and text are specified, the image is put to the left of the text.

Usage example:

     Wt::WContainerWidget *w = new Wt::WContainerWidget();
     Wt::WLabel *label = new Wt::WLabel("Favourite Actress: ", w);
     Wt::WLineEdit *edit = new Wt::WLineEdit("Renee Zellweger", w);
     label->setBuddy(edit);

The widget corresponds to the HTML `<label>` tag. When no buddy is set, it is rendered using an HTML `<span>` or `<div>` to avoid click event handling misbehavior on Microsoft Internet Explorer.

WLabel is an inline widget.

### CSS

This widget does not provide styling, and can be styled using inline or external CSS as appropriate. A label's text may be styled via a nested `<span>` element, and it's image may be styled via a nested `<img>` element.

## Member Function Documentation

WFormWidget* Wt::WLabel::buddy | ( |  | ) | const

Returns the buddy of this label.

See also:
  setBuddy(WFormWidget *)

void Wt::WLabel::propagateSetEnabled | ( | bool | enabled | ) | `[protected, virtual]`

Propagates that a widget was enabled or disabled through children.

When enabling or disabling a widget, you usually also want to disable contained children. This method is called by setDisabled() to propagate its state to all children.

You may want to reimplement this method if they wish to render differently when a widget is disabled. The default implementation will propagate the signal to all children.

Reimplemented from Wt::WInteractWidget.

void Wt::WLabel::setBuddy | ( | WFormWidget * | buddy | ) |

Sets the buddy of this label.

Sets the buddy FormWidget for which this label acts as a proxy.

See also:
  WFormWidget::label(), setBuddy(Ext::FormField *), buddy()

void Wt::WLabel::setBuddy | ( | Ext::FormField * | buddy | ) |

Sets the buddy of this label.

Sets the buddy Ext::FormField for which this label acts as a proxy. When using this method, the result of buddy() is not defined.

See also:
  Ext::FormField::label(), setBuddy(WFormWidget *)

bool Wt::WLabel::setTextFormat | ( | TextFormat | format | ) |

Sets the text format.

The textFormat controls how the string should be interpreted: either as plain text, which is displayed literally, or as XHTML-markup.

When changing the textFormat to Wt::XHTMLText, and the current text is literal (not created using WString::tr()), the current text is parsed using an XML parser which discards malicious tags and attributes silently. When the parser encounters an XML parse error, the textFormat is left unchanged, and this method returns false.

Returns whether the textFormat could be set for the current text.

The default format is Wt::XHTMLText.

void Wt::WLabel::setWordWrap | ( | bool | wordWrap | ) |

Configures word wrapping.

When `wordWrap` is `true`, the widget may break lines, creating a multi-line text. When `wordWrap` is `false`, the text will displayed on a single line, unless the text contains end-of-lines (for Wt::PlainText) or <br /> tags or other block-level tags (for Wt::XHTMLText).

The default value is `false`.

See also:
  wordWrap()

TextFormat Wt::WLabel::textFormat | ( |  | ) | const

Returns the text format.

See also:
  setTextFormat()

bool Wt::WLabel::wordWrap | ( |  | ) | const

Returns whether word wrapping is on.

See also:
  setWordWrap()

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator