#include <Wt/WTabWidget>
Public Types | |
enum | LoadPolicy { LazyLoading, PreLoading } |
When should the contents be loaded ? More... | |
Public Member Functions | |
WTabWidget (WContainerWidget *parent=0) | |
Create a new WTabWidget. | |
WTabWidget (WFlags< AlignmentFlag > layoutAlignment, WContainerWidget *parent=0) | |
Create a new WTabWidget with custom layout alignment. | |
WMenuItem * | addTab (WWidget *child, const WString &label, LoadPolicy=LazyLoading) |
Add a new tab, with child as content, and the given label. | |
void | removeTab (WWidget *widget) |
Removes a tab item. | |
int | count () const |
Return the number of tabs. | |
WWidget * | widget (int index) const |
Get the content widget at the given tab index. | |
int | indexOf (WWidget *widget) const |
Get the index of the given widget. | |
void | setCurrentIndex (int index) |
Activate the tab at index. | |
int | currentIndex () const |
Get the index of the activated tab. | |
void | setCurrentWidget (WWidget *widget) |
Activate the tab showing the given widget. | |
WWidget * | currentWidget () const |
Get the widget of the activated tab. | |
void | setTabEnabled (int index, bool enable) |
Enable or disable a tab. | |
bool | isTabEnabled (int index) const |
Returns if a tab is enabled. | |
void | setTabHidden (int index, bool hidden) |
Hide or show a tab. | |
bool | isTabHidden (int index) const |
Return if a tab is hidden. | |
void | setTabText (int index, const WString &label) |
Change the label for a tab. | |
const WString & | tabText (int index) const |
Get the label for a tab. | |
void | setTabToolTip (int index, const WString &tip) |
Set the tooltip for a tab. | |
const WString & | tabToolTip (int index) const |
Get the tooltip for a tab. | |
void | setInternalPathEnabled (const std::string &basePath="") |
Enable internal paths for items. | |
bool | internalPathEnabled () const |
Returns whether internal paths are enabled. | |
void | setInternalBasePath (const std::string &path) |
Set 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. |
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. If you want an item to fill the contents (e.g. if it is a WContainerWidget whose contents is managed using a layout manager), you should resize the item to 100% height.
This widget uses the following resources:
These files may be found in the resources/ folder of the Wt distribution.
The default value for resourcesURL is "resources/". This value may be overridden with any valid URL which points to the location where these files may be found, by configuring the resourcesURL property in your Wt configuration file.
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(SLOT(this, MyClass::logInternalPath)); examples->setInternalPathEnabled(); examples->setInternalBasePath("/examples");
An example WTabWidget
Wt::WTabWidget::WTabWidget | ( | WFlags< AlignmentFlag > | layoutAlignment, | |
WContainerWidget * | parent = 0 | |||
) |
Create a new WTabWidget with custom layout alignment.
The default constructor will use a layout manager to fit the tab widget within a parent container, and show scrollbars inside a tab if needed.
Here you can override the alignment option for the layout manager, e.g. use Wt::AlignTop | Wt::AlignJustify to not attempt to constrain the height of the tab widget.
WMenuItem * Wt::WTabWidget::addTab | ( | WWidget * | child, | |
const WString & | label, | |||
LoadPolicy | loadPolicy = LazyLoading | |||
) |
Add a new tab, with child as content, and the given label.
Returns the menu item that implements the tab item.
void Wt::WTabWidget::removeTab | ( | WWidget * | widget | ) |
int Wt::WTabWidget::indexOf | ( | WWidget * | widget | ) | const |
Get the index of the given widget.
If the widget is not in this tab widget, then -1 is returned.
void Wt::WTabWidget::setTabEnabled | ( | int | index, | |
bool | enable | |||
) |
Enable or disable a tab.
Enables or disables the tab at index. A disabled tab cannot be activated.
void Wt::WTabWidget::setTabHidden | ( | int | index, | |
bool | hidden | |||
) |
Hide or show a tab.
Hides are shows the tab at index.
void Wt::WTabWidget::setTabToolTip | ( | int | index, | |
const WString & | tip | |||
) |
Set the tooltip for a tab.
The tooltip is shown when the user hovers over the label.
void Wt::WTabWidget::setInternalPathEnabled | ( | const std::string & | basePath = "" |
) |
Enable 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 internal base path (internalBasePath()), which defaults to the internal path (WApplication::internalPath()) but may be changed using setInternalBasePath(), with a '/' appended to turn it into a folder, if needed.
By default, menu interaction does not change the application internal path.
bool Wt::WTabWidget::internalPathEnabled | ( | ) | const |
void Wt::WTabWidget::setInternalBasePath | ( | const std::string & | path | ) |
Set the internal base path.
A '/' is appended to turn it into a folder, if needed.
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/"
.
Signal<int>& Wt::WTabWidget::currentChanged | ( | ) | [inline] |
Signal emitted when the user activates a tab.
The index of the newly activated tab is passed as an argument.