Wt: Wt::WTabWidget Class Reference

Wt 3.3.0

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

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions
Wt::WTabWidget Class Reference

A widget that organizes contents in tab panes. More...

`#include <Wt/WTabWidget>`

Inheritance diagram for Wt::WTabWidget:
[legend]

List of all members.

## Public Types
enum | LoadPolicy { LazyLoading, PreLoading }
| Enumeration to indicate when the contents should be loaded. More...
## Public Member Functions
| WTabWidget (WContainerWidget *parent=0)
| Creates a new tab widget.
WMenuItem * | addTab (WWidget *child, const WString &label, LoadPolicy=LazyLoading)
| Adds a new tab, with child as content, and the given label.
void | removeTab (WWidget *widget)
| Removes a tab item.
int | count () const
| Returns the number of tabs.
WWidget * | widget (int index) const
| Returns the content widget at the given tab index.
int | indexOf (WWidget *widget) const
| Returns the index of the tab of the given content widget.
void | setCurrentIndex (int index)
| Activates the tab at index.
int | currentIndex () const
| Returns the index of the activated tab.
void | setCurrentWidget (WWidget *widget)
| Activates the tab showing the given widget
WWidget * | currentWidget () const
| Returns the widget of the activated tab.
void | setTabEnabled (int index, bool enable)
| Enables or disables a tab.
bool | isTabEnabled (int index) const
| Returns whether a tab is enabled.
void | setTabHidden (int index, bool hidden)
| Hides or shows a tab.
bool | isTabHidden (int index) const
| Returns whether a tab is hidden.
void | setTabCloseable (int index, bool closeable)
| Make it possible to close a tab interactively or by closeTab.
bool | isTabCloseable (int index)
| Returns whether a tab is closeable.
void | setTabText (int index, const WString &label)
| Changes the label for a tab.
const WString & | tabText (int index) const
| Returns the label for a tab.
void | setTabToolTip (int index, const WString &tip)
| Sets the tooltip for a tab.
const WString & | tabToolTip (int index) const
| Returns the tooltip for a tab.
void | setInternalPathEnabled (const std::string &basePath="")
| Enables internal paths for items.
bool | internalPathEnabled () const
| Returns whether internal paths are enabled.
void | setInternalBasePath (const std::string &path)
| Sets the internal base path.
const std::string & | internalBasePath () const
| Returns the internal base path.
Signal< int > & | currentChanged ()
| Signal emitted when the user activates a tab.
void | closeTab (int index)
| Closes a tab at `index`.
Signal< int > & | tabClosed ()
| Signal emitted when the user closes a tab.
WStackedWidget * | contentsStack () const
| Returns the contents stack.

## Detailed Description

A widget that organizes contents in tab panes.

This widget combines a horizontal WMenu with a WStackedWidget, and a tab-like look.

A tab widget will place the tab bar on top of the contents, and fit the contents below it.

Usage example:

     Wt::WTabWidget *examples = new Wt::WTabWidget(this);

     examples->addTab(helloWorldExample(), "Hello World");
     examples->addTab(chartExample(), "Charts");
     examples->addTab(new Wt::WText("A WText"), "WText");

     examples->currentChanged().connect(this, &MyClass::logInternalPath);
     examples->setInternalPathEnabled();
     examples->setInternalBasePath("/examples");

### CSS

The tab widget is styled by the current CSS theme.

An example WTabWidget (default) | An example WTabWidget (polished)

## Member Enumeration Documentation

enum Wt::WTabWidget::LoadPolicy

Enumeration to indicate when the contents should be loaded.

Enumerator:

  LazyLoading | Lazy loading: on first use.
  PreLoading | Pre-loading: before first use.

## Member Function Documentation

WMenuItem * Wt::WTabWidget::addTab | ( | WWidget * | child,
|  | const WString & | label,
|  | LoadPolicy | loadPolicy = `LazyLoading`
| ) |  |

Adds a new tab, with child as content, and the given label.

Returns the menu item that implements the tab item.

void Wt::WTabWidget::closeTab | ( | int | index | ) |

Closes a tab at `index`.

A tab that has been closed is marked as hidden, but not removed from the menu.

See also:
  removeTab(), setTabHidden()

WStackedWidget * Wt::WTabWidget::contentsStack | ( |  | ) | const

Returns the contents stack.

The tab widget is implemented as a WMenu + WStackedWidget which displays the contents. This method returns a reference to this contents stack.

Signal<int>& Wt::WTabWidget::currentChanged | ( |  | ) |

Signal emitted when the user activates a tab.

The index of the newly activated tab is passed as an argument.

int Wt::WTabWidget::indexOf | ( | WWidget * | widget | ) | const

Returns the index of the tab of the given content widget.

If the widget is not in this tab widget, then -1 is returned.

const std::string & Wt::WTabWidget::internalBasePath | ( |  | ) | const

Returns the internal base path.

The default value is the application's internalPath (WApplication::internalPath()) that was recorded when setInternalPathEnabled() was called, and together with each WMenuItem::pathComponent() determines the paths for each item.

For example, if internalBasePath() is `"/examples/"` and pathComponent() for a particular item is `"charts/"`, then the internal path for that item will be `"/examples/charts/"`.

See also:
  setInternalPathEnabled()

bool Wt::WTabWidget::internalPathEnabled | ( |  | ) | const

Returns whether internal paths are enabled.

See also:
  setInternalPathEnabled()

bool Wt::WTabWidget::isTabCloseable | ( | int | index | ) |

Returns whether a tab is closeable.

See also:
  setTabCloseable()

bool Wt::WTabWidget::isTabEnabled | ( | int | index | ) | const

Returns whether a tab is enabled.

See also:
  WMenu::enableItem(), WMenu::disableItem()

void Wt::WTabWidget::removeTab | ( | WWidget * | widget | ) |

Removes a tab item.

The widget itself is not deleted.

See also:
  WMenu::removeItem()

void Wt::WTabWidget::setInternalBasePath | ( | const std::string & | path | ) |

Sets the internal base path.

A '/' is appended to turn it into a folder, if needed.

See also:
  setInternalPathEnabled(), internalBasePath()

void Wt::WTabWidget::setInternalPathEnabled | ( | const std::string & | basePath = `""` | ) |

Enables internal paths for items.

The menu participates in the internal path by changing the internal path when an item has been selected, and listening for path changes to react to path selections. As a consequence this allows the user to bookmark the current menu selection and revisit it later, use back/forward buttons to navigate through history of visited menu items, and allows indexing of pages.

For each menu item, WMenuItem::pathComponent() is appended to the `basePath`, which defaults to the internal path (WApplication::internalPath()). A '/' is appended to the base path, to turn it into a folder, if needed.

By default, menu interaction does not change the application internal path.

See also:
  WMenuItem::setPathComponent().

void Wt::WTabWidget::setTabCloseable | ( | int | index,
|  | bool | closeable
| ) |  |

Make it possible to close a tab interactively or by closeTab.

A tab that has been closed is marked as hidden, but not removed from the menu.

See also:
  removeTab()

void Wt::WTabWidget::setTabEnabled | ( | int | index,
|  | bool | enable
| ) |  |

Enables or disables a tab.

Enables or disables the tab at `index`. A disabled tab cannot be activated.

void Wt::WTabWidget::setTabHidden | ( | int | index,
|  | bool | hidden
| ) |  |

Hides or shows a tab.

Hides or shows the tab at `index`.

void Wt::WTabWidget::setTabToolTip | ( | int | index,
|  | const WString & | tip
| ) |  |

Sets the tooltip for a tab.

The tooltip is shown when the user hovers over the label.

Signal<int>& Wt::WTabWidget::tabClosed | ( |  | ) |

Signal emitted when the user closes a tab.

The index of the closed tab is passed as an argument.

See also:
  closeTab(), setTabCloseable()

const WString & Wt::WTabWidget::tabText | ( | int | index | ) | const

Returns the label for a tab.

See also:
  setTabText()

const WString & Wt::WTabWidget::tabToolTip | ( | int | index | ) | const

Returns the tooltip for a tab.

See also:
  setTabToolTip()

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator