Main Page Widgets Namespaces Book

# Gtk::ComboBox Class Reference
[Widgets]

Inheritance diagram for Gtk::ComboBox:

[legend]

List of all members.

## Detailed Description

A widget used to choose from a list of items.

A ComboBox is a widget that allows the user to choose from a list of valid choices. The ComboBox displays the selected choice. When activated, the ComboBox displays a popup which allows the user to make a new choice. The style in which the selected value is displayed, and the style of the popup is determined by the current theme. It may be similar to a OptionMenu, or similar to a Windows-style combo box.

The ComboBox uses the model-view pattern; the list of valid choices is specified in the form of a tree model, and the display of the choices can be adapted to the data in the model by using cell renderers, as you would in a tree view. This is possible since ComboBox implements the CellLayout interface. The tree model holding the valid choices is not restricted to a flat list, it can be a real tree, and the popup will reflect the tree structure.

The ComboBox widget looks like this:

See also ComboBoxText, which is specialised for a single text column.

## Public Types

typedef TreeView::SlotRowSeparator | SlotRowSeparator

## Public Member Functions

| ComboBox (const Glib::RefPtr<TreeModel>& model)
| Creates a new ComboBox with the model initialized to model.
| ComboBox ()
TreeModel::const_iterator | get_active () const
| Gets an iterator that points to the current active item, if it exists.
TreeModel::iterator | get_active ()
| Gets an iterator that points to the current active item, if it exists.
int | get_active_row_number () const
| Return value: An integer which is the index of the currently active item,.
bool | get_add_tearoffs () const
| Gets the current value of the :add-tearoffs property.
int | get_column_span_column () const
| Returns: the column span column.
bool | get_focus_on_click () const
| Return value: `true` if the combo box grabs focus when it is.
Glib::RefPtr<const TreeModel> | get_model () const
| Return value: A Gtk::TreeModel which was passed during construction.
Glib::RefPtr<TreeModel> | get_model ()
| Return value: A Gtk::TreeModel which was passed during construction.
Glib::RefPtr<const Atk::Object> | get_popup_accessible () const
| Gets the accessible object corresponding to the combo box's popup.
Glib::RefPtr<Atk::Object> | get_popup_accessible ()
| Gets the accessible object corresponding to the combo box's popup.
int | get_row_span_column () const
| Returns: the row span column.
Glib::ustring | get_title () const
| Gets the current title of the menu in tearoff mode.
int | get_wrap_width () const
| Returns: the wrap width.
const GtkComboBox* | gobj () const
| Provides access to the underlying C GtkObject.
GtkComboBox* | gobj ()
| Provides access to the underlying C GtkObject.
void | popdown ()
| Hides the menu or dropdown list of combo_box.
void | popup ()
| Pops up the menu or dropdown list of combo_box.
Glib::PropertyProxy_ReadOnly<int> | property_active () const
| The item which is currently active.
Glib::PropertyProxy<int> | property_active ()
| The item which is currently active.
Glib::PropertyProxy_ReadOnly <bool> | property_add_tearoffs () const
| Whether dropdowns should have a tearoff menu item.
Glib::PropertyProxy<bool> | property_add_tearoffs ()
| Whether dropdowns should have a tearoff menu item.
Glib::PropertyProxy_ReadOnly<int> | property_column_span_column () const
| TreeModel column containing the column span values.
Glib::PropertyProxy<int> | property_column_span_column ()
| TreeModel column containing the column span values.
Glib::PropertyProxy_ReadOnly <bool> | property_focus_on_click () const
| Whether the combo box grabs focus when it is clicked with the mouse.
Glib::PropertyProxy<bool> | property_focus_on_click ()
| Whether the combo box grabs focus when it is clicked with the mouse.
Glib::PropertyProxy_ReadOnly <bool> | property_has_frame () const
| Whether the combo box draws a frame around the child.
Glib::PropertyProxy<bool> | property_has_frame ()
| Whether the combo box draws a frame around the child.
Glib::PropertyProxy_ReadOnly <Glib::RefPtr<TreeModel>> | property_model () const
| The model for the combo box.
Glib::PropertyProxy <Glib::RefPtr<TreeModel>> | property_model ()
| The model for the combo box.
Glib::PropertyProxy_ReadOnly<int> | property_row_span_column () const
| TreeModel column containing the row span values.
Glib::PropertyProxy<int> | property_row_span_column ()
| TreeModel column containing the row span values.
Glib::PropertyProxy_ReadOnly <Glib::ustring> | property_tearoff_title () const
| A title that may be displayed by the window manager when the popup is torn-off.
Glib::PropertyProxy <Glib::ustring> | property_tearoff_title ()
| A title that may be displayed by the window manager when the popup is torn-off.
Glib::PropertyProxy_ReadOnly<int> | property_wrap_width () const
| Wrap width for laying out the items in a grid.
Glib::PropertyProxy<int> | property_wrap_width ()
| Wrap width for laying out the items in a grid.
void | set_active (const TreeModel::iterator& iter)
| Sets the current active item to be the one referenced by iter.
void | set_active (int index)
| Sets the active item of combo_box to be the item at index.
void | set_add_tearoffs (bool add_tearoffs=true)
| Sets whether the popup menu should have a tearoff menu item.
void | set_column_span_column (int column_span)
| Sets the column with column span information for combo_box to be column_span.
void | set_focus_on_click (bool focus_on_click=true)
| Sets whether the combo box will grab focus when it is clicked with the mouse.
void | set_model (const Glib::RefPtr<TreeModel>& model)
| Sets the model used by combo_box to be model.
void | set_row_separator_func (const SlotRowSeparator& slot)
| Sets the row separator function, which is used to determine whether a row should be drawn as a separator.
void | set_row_span_column (int row_span)
| Sets the column with row span information for combo_box to be row_span.
void | set_title (const Glib::ustring& title)
| Sets the menu's title in tearoff mode.
void | set_wrap_width (int width)
| Sets the wrap width of combo_box to be width.
Glib::SignalProxy0<void> | signal_changed ()
| The changed signal gets emitted when the active item is changed.
void | unset_active ()
| Causes no item to be active.
void | unset_row_separator_func ()
| Causes no separators to be drawn.
virtual | ~ComboBox ()

## Protected Member Functions

virtual void | on_changed ()

## Related Functions

(Note that these are not member functions.)
Gtk::ComboBox* | wrap (GtkComboBox* object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Member Typedef Documentation

typedef TreeView::SlotRowSeparator Gtk::ComboBox::SlotRowSeparator

## Constructor & Destructor Documentation

virtual Gtk::ComboBox::~ComboBox | ( |  | ) | `[virtual]`

Gtk::ComboBox::ComboBox | ( |  | ) |

Gtk::ComboBox::ComboBox | ( | const Glib::RefPtr<TreeModel>& | model | ) | `[explicit]`

Creates a new ComboBox with the model initialized to model.

## Member Function Documentation

TreeModel::const_iterator Gtk::ComboBox::get_active | ( |  | ) | const

Gets an iterator that points to the current active item, if it exists.

Returns:
  The iterator.

TreeModel::iterator Gtk::ComboBox::get_active | ( |  | ) |

Gets an iterator that points to the current active item, if it exists.

Returns:
  The iterator.

int Gtk::ComboBox::get_active_row_number | ( |  | ) | const

Return value: An integer which is the index of the currently active item,.

Returns:
  An integer which is the index of the currently active item, or -1 if there's no active item.

Since gtkmm 2.4:

bool Gtk::ComboBox::get_add_tearoffs | ( |  | ) | const

Gets the current value of the :add-tearoffs property.

Returns:
  The current value of the :add-tearoffs property.

int Gtk::ComboBox::get_column_span_column | ( |  | ) | const

Returns: the column span column.

Returns:
  The column span column.

Since gtkmm 2.6:

bool Gtk::ComboBox::get_focus_on_click | ( |  | ) | const

Return value: `true` if the combo box grabs focus when it is.

Returns:
  `true` if the combo box grabs focus when it is clicked with the mouse.

Since gtkmm 2.6:

Glib::RefPtr<const TreeModel> Gtk::ComboBox::get_model | ( |  | ) | const

Return value: A Gtk::TreeModel which was passed during construction.

Returns:
  A Gtk::TreeModel which was passed during construction.

Since gtkmm 2.4:

Glib::RefPtr<TreeModel> Gtk::ComboBox::get_model | ( |  | ) |

Return value: A Gtk::TreeModel which was passed during construction.

Returns:
  A Gtk::TreeModel which was passed during construction.

Since gtkmm 2.4:

Glib::RefPtr<const Atk::Object> Gtk::ComboBox::get_popup_accessible | ( |  | ) | const

Gets the accessible object corresponding to the combo box's popup.

This function is mostly intended for use by accessibility technologies; applications should have little use for it.

Returns:
  The accessible object corresponding to the combo box's popup.

Since gtkmm 2.6:

Glib::RefPtr<Atk::Object> Gtk::ComboBox::get_popup_accessible | ( |  | ) |

Gets the accessible object corresponding to the combo box's popup.

This function is mostly intended for use by accessibility technologies; applications should have little use for it.

Returns:
  The accessible object corresponding to the combo box's popup.

Since gtkmm 2.6:

int Gtk::ComboBox::get_row_span_column | ( |  | ) | const

Returns: the row span column.

Returns:
  The row span column.

Since gtkmm 2.6:

Glib::ustring Gtk::ComboBox::get_title | ( |  | ) | const

Gets the current title of the menu in tearoff mode.

See set_add_tearoffs().

Returns:
  The menu's title in tearoff mode. This is an internal copy of the string which must not be freed.

Since gtkmm 2.10:

int Gtk::ComboBox::get_wrap_width | ( |  | ) | const

Returns: the wrap width.

Returns:
  The wrap width.

Since gtkmm 2.6:

const GtkComboBox* Gtk::ComboBox::gobj | ( |  | ) | const`[inline]`

Provides access to the underlying C GtkObject.

Reimplemented from Gtk::Bin.

Reimplemented in Gtk::ComboBoxEntry.

GtkComboBox* Gtk::ComboBox::gobj | ( |  | ) | `[inline]`

Provides access to the underlying C GtkObject.

Reimplemented from Gtk::Bin.

Reimplemented in Gtk::ComboBoxEntry.

virtual void Gtk::ComboBox::on_changed | ( |  | ) | `[protected, virtual]`

void Gtk::ComboBox::popdown | ( |  | ) |

Hides the menu or dropdown list of combo_box.

This function is mostly intended for use by accessibility technologies; applications should have little use for it.

Since gtkmm 2.4:

void Gtk::ComboBox::popup | ( |  | ) |

Pops up the menu or dropdown list of combo_box.

This function is mostly intended for use by accessibility technologies; applications should have little use for it.

Since gtkmm 2.4:

Glib::PropertyProxy_ReadOnly<int> Gtk::ComboBox::property_active | ( |  | ) | const

The item which is currently active.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy<int> Gtk::ComboBox::property_active | ( |  | ) |

The item which is currently active.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<bool> Gtk::ComboBox::property_add_tearoffs | ( |  | ) | const

Whether dropdowns should have a tearoff menu item.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy<bool> Gtk::ComboBox::property_add_tearoffs | ( |  | ) |

Whether dropdowns should have a tearoff menu item.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<int> Gtk::ComboBox::property_column_span_column | ( |  | ) | const

TreeModel column containing the column span values.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy<int> Gtk::ComboBox::property_column_span_column | ( |  | ) |

TreeModel column containing the column span values.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<bool> Gtk::ComboBox::property_focus_on_click | ( |  | ) | const

Whether the combo box grabs focus when it is clicked with the mouse.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy<bool> Gtk::ComboBox::property_focus_on_click | ( |  | ) |

Whether the combo box grabs focus when it is clicked with the mouse.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<bool> Gtk::ComboBox::property_has_frame | ( |  | ) | const

Whether the combo box draws a frame around the child.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy<bool> Gtk::ComboBox::property_has_frame | ( |  | ) |

Whether the combo box draws a frame around the child.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<Glib::RefPtr<TreeModel>> Gtk::ComboBox::property_model | ( |  | ) | const

The model for the combo box.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy<Glib::RefPtr<TreeModel>> Gtk::ComboBox::property_model | ( |  | ) |

The model for the combo box.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<int> Gtk::ComboBox::property_row_span_column | ( |  | ) | const

TreeModel column containing the row span values.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy<int> Gtk::ComboBox::property_row_span_column | ( |  | ) |

TreeModel column containing the row span values.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<Glib::ustring> Gtk::ComboBox::property_tearoff_title | ( |  | ) | const

A title that may be displayed by the window manager when the popup is torn-off.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy<Glib::ustring> Gtk::ComboBox::property_tearoff_title | ( |  | ) |

A title that may be displayed by the window manager when the popup is torn-off.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly<int> Gtk::ComboBox::property_wrap_width | ( |  | ) | const

Wrap width for laying out the items in a grid.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy<int> Gtk::ComboBox::property_wrap_width | ( |  | ) |

Wrap width for laying out the items in a grid.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

void Gtk::ComboBox::set_active | ( | const TreeModel::iterator& | iter | ) |

Sets the current active item to be the one referenced by iter.

iter must correspond to a path of depth one.

Since gtkmm 2.4:

Parameters:

  | iter | The Gtk::TreeIter.

void Gtk::ComboBox::set_active | ( | int | index | ) |

Sets the active item of combo_box to be the item at index.

Since gtkmm 2.4:

Parameters:

  | index | An index in the model passed during construction, or -1 to have no active item.

void Gtk::ComboBox::set_add_tearoffs | ( | bool | add_tearoffs = `true` | ) |

Sets whether the popup menu should have a tearoff menu item.

Since gtkmm 2.6:

Parameters:

  | add_tearoffs | `true` to add tearoff menu items.

void Gtk::ComboBox::set_column_span_column | ( | int | column_span | ) |

Sets the column with column span information for combo_box to be column_span.

The column span column contains integers which indicate how many columns an item should span.

Since gtkmm 2.4:

Parameters:

  | column_span | A column in the model passed during construction.

void Gtk::ComboBox::set_focus_on_click | ( | bool | focus_on_click = `true` | ) |

Sets whether the combo box will grab focus when it is clicked with the mouse.

Making mouse clicks not grab focus is useful in places like toolbars where you don't want the keyboard focus removed from the main area of the application.

Since gtkmm 2.6:

Parameters:

  | focus_on_click | Whether the combo box grabs focus when clicked with the mouse.

void Gtk::ComboBox::set_model | ( | const Glib::RefPtr<TreeModel>& | model | ) |

Sets the model used by combo_box to be model.

Will unset a previously set model (if applicable). If model is `0`, then it will unset the model.

Note that this function does not clear the cell renderers, you have to call Gtk::CellLayout::clear() yourself if you need to set up different cell renderers for the new model.

Since gtkmm 2.4:

Parameters:

  | model | A Gtk::TreeModel.

void Gtk::ComboBox::set_row_separator_func | ( | const SlotRowSeparator& | slot | ) |

Sets the row separator function, which is used to determine whether a row should be drawn as a separator.

See also unset_row_separator_func().

Parameters:

  | slot | The callback.

void Gtk::ComboBox::set_row_span_column | ( | int | row_span | ) |

Sets the column with row span information for combo_box to be row_span.

The row span column contains integers which indicate how many rows an item should span.

Since gtkmm 2.4:

Parameters:

  | row_span | A column in the model passed during construction.

void Gtk::ComboBox::set_title | ( | const Glib::ustring & | title | ) |

Sets the menu's title in tearoff mode.

Since gtkmm 2.10:

Parameters:

  | title | A title for the menu in tearoff mode.

void Gtk::ComboBox::set_wrap_width | ( | int | width | ) |

Sets the wrap width of combo_box to be width.

The wrap width is basically the preferred number of columns when you want the popup to be layed out in a table.

Since gtkmm 2.4:

Parameters:

  | width | Preferred number of columns.

Glib::SignalProxy0< void > Gtk::ComboBox::signal_changed | ( |  | ) |

The changed signal gets emitted when the active item is changed.

This can be due to the user selecting a different item from the list, or due to a call to set_active_iter().

Prototype:
  `void on_my_changed()`

void Gtk::ComboBox::unset_active | ( |  | ) |

Causes no item to be active.

See also set_active().

void Gtk::ComboBox::unset_row_separator_func | ( |  | ) |

Causes no separators to be drawn.

## Friends And Related Function Documentation

Gtk::ComboBox* wrap | ( | GtkComboBox * | object,
|  | bool | take_copy = `false` |
| ) |  |  | `[related]`

A Glib::wrap() method for this object.

Parameters:

  | object | The C instance.
  | take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns:
  A C++ instance that wraps this C instance.

The documentation for this class was generated from the following file:

- combobox.h