Wt
3.2.3
|
A selection box allows selection from a list of options. More...
#include <Wt/WSelectionBox>
Public Member Functions | |
WSelectionBox (WContainerWidget *parent=0) | |
Constructor. | |
int | verticalSize () const |
Returns the number of items that are visible. | |
void | setVerticalSize (int items) |
Sets the number of items that are visible. | |
void | setSelectionMode (SelectionMode mode) |
Sets the selection mode. | |
SelectionMode | selectionMode () const |
Returns the selection mode. | |
const std::set< int > & | selectedIndexes () const |
Returns the current selection (in Wt::ExtendedSelection mode). | |
void | setSelectedIndexes (const std::set< int > &selection) |
Sets the selection (in Wt::ExtendedSelection mode). | |
void | clearSelection () |
Clears the current selection. |
A selection box allows selection from a list of options.
By default, a selection box may be used to let the user select one item from a list. This may be changed to multiple selection mode using setSelectionMode().
The current selection may be set and read using setCurrentIndex() and currentIndex(), for SingleSelection mode, or setSelectedIndexes() and selectedIndexes() for Wt::ExtendedSelection mode. The activated() and sactivated() signals are not emited in the Wt::ExtendedSelection mode, use the changed() signal changed().
WSelectionBox is an MVC view class, using a simple string list model by default. The model may be populated using WComboBox::addItem() or WComboBox::insertItem() and the contents can be cleared through clear(). These methods manipulate the underlying model().
To use the selectionbox with a custom model instead of the default WStringListModel, use setModel().
Usage example:
Wt::WSelectionBox *selectionBox = new Wt::WSelectionBox(this); selectionBox->addItem("Clint Eastwood"); selectionBox->addItem("Mick Jagger"); selectionBox->addItem("Johnny Depp"); selectionBox->addItem("Kate Winslet"); selectionBox->setCurrentIndex(2); // Johnny Depp selectionBox->activated().connect(this, &MyWidget::comboChanged);
WSelectionBox is an inline widget.
The widget corresponds to the HTML <select>
tag and does not provide styling. It can be styled using inline or external CSS as appropriate.
void Wt::WSelectionBox::clearSelection | ( | ) |
Clears the current selection.
Clears the current selection.
const std::set<int>& Wt::WSelectionBox::selectedIndexes | ( | ) | const |
Returns the current selection (in Wt::ExtendedSelection mode).
Get the list of currently selected items. This method is only defined when selectionMode() is Wt::ExtendedSelection. Otherwise, you should use currentIndex() to get item currently selected.
SelectionMode Wt::WSelectionBox::selectionMode | ( | ) | const |
Returns the selection mode.
void Wt::WSelectionBox::setSelectedIndexes | ( | const std::set< int > & | selection | ) |
Sets the selection (in Wt::ExtendedSelection mode).
For an Wt::ExtendedSelection mode, set the list of currently selected items.
void Wt::WSelectionBox::setSelectionMode | ( | SelectionMode | mode | ) |
Sets the selection mode.
The default selection mode is SingleSelection. You can change to Wt::ExtendedSelection to allow selection of multiple items.
void Wt::WSelectionBox::setVerticalSize | ( | int | items | ) |
Sets the number of items that are visible.
If more items are available, a scroll-bar is provided.