Next: , Previous: GtkTreeStore, Up: Top


54 GtkComboBox

A widget used to choose from a list of items

54.1 Overview

A <gtk-combo-box> is a widget that allows the user to choose from a list of valid choices. The <gtk-combo-box> displays the selected choice. When activated, the <gtk-combo-box> 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 <gtk-option-menu>, or similar to a Windows-style combo box.

Unlike its predecessors <gtk-combo> and <gtk-option-menu>, the <gtk-combo-box> 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 <gtk-combo-box> implements the <gtk-cell-layout> 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.

In addition to the model-view API, <gtk-combo-box> offers a simple API which is suitable for text-only combo boxes, and hides the complexity of managing the data in a model. It consists of the functions gtk-combo-box-new-text, gtk-combo-box-append-text, gtk-combo-box-insert-text, gtk-combo-box-prepend-text, gtk-combo-box-remove-text and gtk-combo-box-get-active-text.

54.2 Usage

— Class: <gtk-combo-box>

Derives from <gtk-cell-layout>, <gtk-cell-editable>, <gtk-bin>.

This class defines the following slots:

model
The model for the combo box
wrap-width
Wrap width for laying out the items in a grid
row-span-column
TreeModel column containing the row span values
column-span-column
TreeModel column containing the column span values
active
The item which is currently active
add-tearoffs
Whether dropdowns should have a tearoff menu item
tearoff-title
A title that may be displayed by the window manager when the popup is torn-off
has-frame
Whether the combo box draws a frame around the child
focus-on-click
Whether the combo box grabs focus when it is clicked with the mouse
popup-shown
Whether the combo's dropdown is shown
— Signal on <gtk-combo-box>: changed

The changed signal is emitted when the active item is changed. The can be due to the user selecting a different item from the list, or due to a call to gtk-combo-box-set-active-iter. It will also be emitted while typing into a GtkComboBoxEntry, as well as when selecting an item from the GtkComboBoxEntry's list.

Since 2.4

— Signal on <gtk-combo-box>: move-active (arg0 <gtk-scroll-type>)

undocumented

— Signal on <gtk-combo-box>: popup

undocumented

— Signal on <gtk-combo-box>: popdown ⇒ <gboolean>

undocumented

— Function: gtk-combo-box-new ⇒  (ret <gtk-widget>)

Creates a new empty <gtk-combo-box>.

ret
A new <gtk-combo-box>.

Since 2.4

— Function: gtk-combo-box-new-with-model (model <gtk-tree-model>) ⇒  (ret <gtk-widget>)

Creates a new <gtk-combo-box> with the model initialized to model.

model
A <gtk-tree-model>.
ret
A new <gtk-combo-box>.

Since 2.4

— Function: gtk-combo-box-get-wrap-width (self <gtk-combo-box>) ⇒  (ret int)
— Method: get-wrap-width

Returns the wrap width which is used to determine the number of columns for the popup menu. If the wrap width is larger than 1, the combo box is in table mode.

combo-box
A <gtk-combo-box>.
ret
the wrap width.

Since 2.6

— Function: gtk-combo-box-set-wrap-width (self <gtk-combo-box>) (width int)
— Method: set-wrap-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.

combo-box
A <gtk-combo-box>.
width
Preferred number of columns.

Since 2.4

— Function: gtk-combo-box-get-row-span-column (self <gtk-combo-box>) ⇒  (ret int)
— Method: get-row-span-column

Returns the column with row span information for combo-box.

combo-box
A <gtk-combo-box>.
ret
the row span column.

Since 2.6

— Function: gtk-combo-box-set-row-span-column (self <gtk-combo-box>) (row_span int)
— Method: set-row-span-column

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.

combo-box
A <gtk-combo-box>.
row-span
A column in the model passed during construction.

Since 2.4

— Function: gtk-combo-box-get-active (self <gtk-combo-box>) ⇒  (ret int)
— Method: get-active

Returns the index of the currently active item, or -1 if there's no active item. If the model is a non-flat treemodel, and the active item is not an immediate child of the root of the tree, this function returns ‘gtk_tree_path_get_indices (path)[0]’, where ‘path’ is the <gtk-tree-path> of the active item.

combo-box
A <gtk-combo-box>.
ret
An integer which is the index of the currently active item, or -1 if there's no active item.

Since 2.4

— Function: gtk-combo-box-set-active (self <gtk-combo-box>) (index_ int)
— Method: set-active

Sets the active item of combo-box to be the item at index.

combo-box
A <gtk-combo-box>.
index
An index in the model passed during construction, or -1 to have no active item.

Since 2.4

— Function: gtk-combo-box-get-active-iter (self <gtk-combo-box>) (iter <gtk-tree-iter>) ⇒  (ret bool)
— Method: get-active-iter

Sets iter to point to the current active item, if it exists.

combo-box
A <gtk-combo-box>
iter
The uninitialized <gtk-tree-iter>.
ret
#t’, if iter was set

Since 2.4

— Function: gtk-combo-box-set-active-iter (self <gtk-combo-box>) (iter <gtk-tree-iter>)
— Method: set-active-iter

Sets the current active item to be the one referenced by iter. iter must correspond to a path of depth one.

combo-box
A <gtk-combo-box>
iter
The <gtk-tree-iter>.

Since 2.4

— Function: gtk-combo-box-get-model (self <gtk-combo-box>) ⇒  (ret <gtk-tree-model>)
— Method: get-model

Returns the <gtk-tree-model> which is acting as data source for combo-box.

combo-box
A <gtk-combo-box>.
ret
A <gtk-tree-model> which was passed during construction.

Since 2.4

— Function: gtk-combo-box-set-model (self <gtk-combo-box>) (model <gtk-tree-model>)
— Method: set-model

Sets the model used by combo-box to be model. Will unset a previously set model (if applicable). If model is ‘#f’, then it will unset the model.

Note that this function does not clear the cell renderers, you have to call gtk-combo-box-cell-layout-clear yourself if you need to set up different cell renderers for the new model.

combo-box
A <gtk-combo-box>.
model
A <gtk-tree-model>.

Since 2.4

— Function: gtk-combo-box-new-text ⇒  (ret <gtk-widget>)

Convenience function which constructs a new text combo box, which is a <gtk-combo-box> just displaying strings. If you use this function to create a text combo box, you should only manipulate its data source with the following convenience functions: gtk-combo-box-append-text, gtk-combo-box-insert-text, gtk-combo-box-prepend-text and gtk-combo-box-remove-text.

ret
A new text combo box.

Since 2.4

— Function: gtk-combo-box-append-text (self <gtk-combo-box>) (text mchars)
— Method: append-text

Appends string to the list of strings stored in combo-box. Note that you can only use this function with combo boxes constructed with gtk-combo-box-new-text.

combo-box
A <gtk-combo-box> constructed using gtk-combo-box-new-text.
text
A string.

Since 2.4

— Function: gtk-combo-box-insert-text (self <gtk-combo-box>) (position int) (text mchars)
— Method: insert-text

Inserts string at position in the list of strings stored in combo-box. Note that you can only use this function with combo boxes constructed with gtk-combo-box-new-text.

combo-box
A <gtk-combo-box> constructed using gtk-combo-box-new-text.
position
An index to insert text.
text
A string.

Since 2.4

— Function: gtk-combo-box-prepend-text (self <gtk-combo-box>) (text mchars)
— Method: prepend-text

Prepends string to the list of strings stored in combo-box. Note that you can only use this function with combo boxes constructed with gtk-combo-box-new-text.

combo-box
A <gtk-combo-box> constructed with gtk-combo-box-new-text.
text
A string.

Since 2.4

— Function: gtk-combo-box-remove-text (self <gtk-combo-box>) (position int)
— Method: remove-text

Removes the string at position from combo-box. Note that you can only use this function with combo boxes constructed with gtk-combo-box-new-text.

combo-box
A <gtk-combo-box> constructed with gtk-combo-box-new-text.
position
Index of the item to remove.

Since 2.4

— Function: gtk-combo-box-get-active-text (self <gtk-combo-box>) ⇒  (ret mchars)
— Method: get-active-text

Returns the currently active string in combo-box or ‘#f’ if none is selected. Note that you can only use this function with combo boxes constructed with gtk-combo-box-new-text and with <gtk-combo-box-entry>s.

combo-box
A <gtk-combo-box> constructed with gtk-combo-box-new-text.
ret
a newly allocated string containing the currently active text.

Since 2.6

— Function: gtk-combo-box-popup (self <gtk-combo-box>)
— Method: 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.

combo-box
a <gtk-combo-box>

Since 2.4

— Function: gtk-combo-box-popdown (self <gtk-combo-box>)
— Method: 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.

combo-box
a <gtk-combo-box>

Since 2.4

— Function: gtk-combo-box-get-popup-accessible (self <gtk-combo-box>) ⇒  (ret <atk-object>)
— Method: 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.

combo-box
a <gtk-combo-box>
ret
the accessible object corresponding to the combo box's popup.

Since 2.6

— Function: gtk-combo-box-set-add-tearoffs (self <gtk-combo-box>) (add_tearoffs bool)
— Method: set-add-tearoffs

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

combo-box
a <gtk-combo-box>
add-tearoffs
#t’ to add tearoff menu items

Since 2.6

— Function: gtk-combo-box-get-add-tearoffs (self <gtk-combo-box>) ⇒  (ret bool)
— Method: get-add-tearoffs

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

combo-box
a <gtk-combo-box>
ret
the current value of the :add-tearoffs property.
— Function: gtk-combo-box-set-title (self <gtk-combo-box>) (title mchars)
— Method: set-title

Sets the menu's title in tearoff mode.

combo-box
a <gtk-combo-box>
title
a title for the menu in tearoff mode.

Since 2.10

— Function: gtk-combo-box-get-title (self <gtk-combo-box>) ⇒  (ret mchars)
— Method: get-title

Gets the current title of the menu in tearoff mode. See gtk-combo-box-set-add-tearoffs.

combo-box
a <gtk-combo-box>
ret
the menu's title in tearoff mode. This is an internal copy of the string which must not be freed.

Since 2.10

— Function: gtk-combo-box-set-focus-on-click (self <gtk-combo-box>) (focus_on_click bool)
— Method: set-focus-on-click

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.

combo
a <gtk-combo-box>
focus-on-click
whether the combo box grabs focus when clicked with the mouse

Since 2.6

— Function: gtk-combo-box-get-focus-on-click (self <gtk-combo-box>) ⇒  (ret bool)
— Method: get-focus-on-click

Returns whether the combo box grabs focus when it is clicked with the mouse. See gtk-combo-box-set-focus-on-click.

combo
a <gtk-combo-box>
ret
#t’ if the combo box grabs focus when it is clicked with the mouse.

Since 2.6