Wt: Wt::WImage Class Reference

Wt 3.3.0

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

- Class List
- Class Hierarchy
- Class Members

Public Member Functions
Wt::WImage Class Reference

A widget that displays an image. More...

`#include <Wt/WImage>`

Inheritance diagram for Wt::WImage:
[legend]

List of all members.

## Public Member Functions
| WImage (WContainerWidget *parent=0)
| Creates an empty image widget.
| WImage (const WLink &imageLink, WContainerWidget *parent=0)
| Creates an image widget with a given image link.
| WImage (const WLink &imageLink, const WString &altText, WContainerWidget *parent=0)
| Creates an image widget with a given image link and alternate text.
void | setAlternateText (const WString &text)
| Sets an alternate text.
const WString & | alternateText () const
| Returns the alternate text.
void | setImageLink (const WLink &link)
| Sets the image link.
const WLink & | imageLink () const
| Returns the image link.
void | setImageRef (const std::string &url)
| Sets the image URL (deprecated).
const std::string | imageRef () const
| Returns the image URL (deprecated).
void | setResource (WResource *resource)
| Sets the image resource (deprecated).
WResource * | resource () const
| Returns the image resource (deprecated.
void | addArea (WAbstractArea *area)
| Adds an interactive area.
void | insertArea (int index, WAbstractArea *area)
| Inserts an interactive area.
void | removeArea (WAbstractArea *area)
| Removes an interactive area.
WAbstractArea * | area (int index) const
| Returns the interactive area at the given index.
const std::vector < WAbstractArea * > | areas () const
| Returns the interactive areas set for this widget.
EventSignal & | imageLoaded ()
| Event emitted when the image was loaded.

## Detailed Description

A widget that displays an image.

The image may be specified either as a URL, or may be dynamically generated by a WResource.

You may listen to events by attaching event listeners to signals such as clicked(). Since mouse events pass the coordinates through a WMouseEvent object, it is possible to react to clicks in specific parts of the image. An alternative is to define interactive areas on the image using addArea(), which in addition allows to have customized tool tips for certain image areas (using WAbstractArea::setToolTip()).

Usage example:

     Wt::WImage *img = new Wt::WImage("images/johnny_cash.png", this);
     img->setAlternateText("Johnny Cash sings a song");

WImage is an inline widget.

### CSS

The widget corresponds to the HTML `<img>` tag and does not provide styling. It can be styled using inline or external CSS as appropriate.

See also:
  WResource, WPaintedWidget

## Constructor & Destructor Documentation

Wt::WImage::WImage | ( | const WLink & | imageLink,
|  | WContainerWidget * | parent = `0`
| ) |  |

Creates an image widget with a given image link.

The `imageLink` may link to a URL or resource.

Wt::WImage::WImage | ( | const WLink & | imageLink,
|  | const WString & | altText,
|  | WContainerWidget * | parent = `0`
| ) |  |

Creates an image widget with a given image link and alternate text.

The `imageLink` may link to a URL or resource.

## Member Function Documentation

void Wt::WImage::addArea | ( | WAbstractArea * | area | ) |

Adds an interactive area.

Adds the `area` which listens to events in a specific region of the image. Areas are organized in an indexed list, to which the given `area` is appended. When areas overlap, the area with the lowest index receives the event.

Ownership of the `area` is transferred to the image.

See also:
  insertArea(int, WAbstractArea *)

Note:
  Currently it is not possible to add a first area after the image has been rendered. If you want to use interactive areas you need to add one immediately.

const WString& Wt::WImage::alternateText | ( |  | ) | const

Returns the alternate text.

See also:
  setAlternateText()

WAbstractArea * Wt::WImage::area | ( | int | index | ) | const

Returns the interactive area at the given index.

Returns `0` if `index` was invalid.

See also:
  insertArea(int, WAbstractArea *)

const std::vector< WAbstractArea * > Wt::WImage::areas | ( |  | ) | const

Returns the interactive areas set for this widget.

See also:
  addArea()

const WLink& Wt::WImage::imageLink | ( |  | ) | const

Returns the image link.

See also:
  setLink()

const std::string Wt::WImage::imageRef | ( |  | ) | const

Returns the image URL (deprecated).

When the image is specified as a resource, this returns the current resource URL.

Deprecated:
  Use imageLink() instead.

void Wt::WImage::insertArea | ( | int | index,
|  | WAbstractArea * | area
| ) |  |

Inserts an interactive area.

Inserts the `area` which listens to events in the coresponding area of the image. Areas are organized in a list, and the area is inserted at index `index`. When areas overlap, the area with the lowest index receives the event.

Ownership of the `area` is transferred to the image.

See also:
  addArea(WAbstractArea *)

Note:
  Currently it is not possible to add a first area after the image has been rendered. If you want to use interactive areas you need to add one immediately.

void Wt::WImage::removeArea | ( | WAbstractArea * | area | ) |

Removes an interactive area.

Removes the `area` from this widget, and also returns the ownership.

See also:
  addArea(WAbstractArea *)

WResource * Wt::WImage::resource | ( |  | ) | const

Returns the image resource (deprecated.

Returns `0` if no image resource was set.

Deprecated:
  Use setImageLink() instead.

void Wt::WImage::setAlternateText | ( | const WString & | text | ) |

Sets an alternate text.

The alternate text should provide a fallback for browsers that do not display an image. If no sensible fallback text can be provided, an empty text is preferred over nonsense.

This should not be confused with toolTip() text, which provides additional information that is displayed when the mouse hovers over the image.

The default alternate text is an empty text ("").

See also:
  alternateText()

void Wt::WImage::setImageLink | ( | const WLink & | link | ) |

Sets the image link.

The image may be specified as a URL or as a resource. A resource specifies application-dependent content, which may be used to generate an image on demand.

void Wt::WImage::setImageRef | ( | const std::string & | url | ) |

Sets the image URL (deprecated).

Deprecated:
  Use setImageLink() instead.

void Wt::WImage::setResource | ( | WResource * | resource | ) |

Sets the image resource (deprecated).

Deprecated:
  Use setImageLink() instead.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator