Wt::WComboBox Class Reference
[Model/view system]

A widget that provides a drop-down combo-box control. More...

#include <Wt/WComboBox>

Inheritance diagram for Wt::WComboBox:

Inheritance graph
[legend]

List of all members.

Public Slots

void clear ()
 Clear all items.

Public Member Functions

 WComboBox (WContainerWidget *parent=0)
 Create an empty combo-box with optional parent.
void addItem (const WString &text)
 Add an option item.
int count () const
 Get the number of items.
int currentIndex () const
 Get the currently selected item.
void insertItem (int index, const WString &text)
 Insert an item at the specified position.
void removeItem (int index)
 Remove the item at the specified position.
void setCurrentIndex (int index)
 Change the current selection.
void setItemText (int index, const WString &text)
 Change the text for a specified option.
const WString currentText () const
 Get the text of the currently selected item.
const WString itemText (int index) const
 Get the text of a particular item.
void setModel (WAbstractItemModel *model)
 Set the model to be used for the items.
void setModelColumn (int index)
 Set the column in the model to be used for the items.
WAbstractItemModelmodel () const
 Return the data model.
int findText (const WString &text, MatchFlags flags=MatchFlags(MatchExactly|MatchCaseSensitive))
 Returns the index of the first item that matches a text.
WValidator::State validate ()
 Validate the field.
virtual void refresh ()
 Refresh the widget.

Public Attributes

Signal< int > activated
 Signal emitted when the selection changed.
Signal< WStringsactivated
 Signal emitted when the selection changed.


Detailed Description

A widget that provides a drop-down combo-box control.

A combo box provides the user with a choice of options, from which one option may be selected.

WComboBox is a MVC component, and uses a simple string list model for convenience. Use addItem(const WString&) or insertItem(int, const WString&) to populate the combo-box. All the content can be cleared through clear(). The methods manipulate the underlying model.

To use the combo box with a custom model instead of the default WStringListModel, use setModel().

To act on a new selection, either connect a slot to the changed, activated<int> or sactivated<WString> signals.

At all times, the current selection index is available through currentIndex() or the text using currentText().

WComboBox is an inline widget.


Member Function Documentation

void Wt::WComboBox::addItem ( const WString text  ) 

Add an option item.

Equivalent to insertItem (count(), text).

int Wt::WComboBox::currentIndex (  )  const

Get the currently selected item.

If no item is currently selected, the method returns -1.

The default value is 0, unless the combo box is empty.

void Wt::WComboBox::insertItem ( int  index,
const WString text 
)

Insert an item at the specified position.

The item is inserted in the underlying model at position index. This requires that the model() is editable.

See also:
addItem(const WString&), removeItem(int)

void Wt::WComboBox::removeItem ( int  index  ) 

Remove the item at the specified position.

The item is removed from the underlying model. This requires that the model() is editable.

See also:
insertItem(index, const WString&), clear()

void Wt::WComboBox::setCurrentIndex ( int  index  ) 

Change the current selection.

Specify a value of -1 for index to clear the selection.

void Wt::WComboBox::setItemText ( int  index,
const WString text 
)

Change the text for a specified option.

The text for the item at position index is changed. This requires that the model() is editable.

const WString Wt::WComboBox::currentText (  )  const

Get the text of the currently selected item.

See also:
currentIndex(), itemText(int)

const WString Wt::WComboBox::itemText ( int  index  )  const

Get the text of a particular item.

See also:
setItemText(int, const WString&), currentText()

void Wt::WComboBox::setModel ( WAbstractItemModel model  ) 

Set the model to be used for the items.

The model may not be 0, and ownership of the model is not transferred.

The default value is a WStringListModel that is owned by the the combo box and which will be deleted together with the combo box.

See also:
setModelColumn(int)

void Wt::WComboBox::setModelColumn ( int  index  ) 

Set the column in the model to be used for the items.

The column index in the model will be used to retrieve data.

The default value is 0.

See also:
setModel()

WAbstractItemModel* Wt::WComboBox::model (  )  const [inline]

Return the data model.

See also:
setModel()

void Wt::WComboBox::refresh (  )  [virtual]

Refresh the widget.

The refresh method is invoked when the locale is changed using WApplication::setLocale() or when the user hit the refresh button.

The widget must actualize its contents in response.

Reimplemented from Wt::WWebWidget.

void Wt::WComboBox::clear (  )  [slot]

Clear all items.

Removes all items from the underlying model. This requires that the model() is editable.


Member Data Documentation

Signal emitted when the selection changed.

The newly selected item is passed as an argument.

See also:
sactivated, currentIndex()

Signal emitted when the selection changed.

The newly selected text is passed as an argument.

See also:
activated, currentText()


Generated on Mon Jan 26 14:14:06 2009 for Wt by doxygen 1.5.6