A widget used to choose from a list of items
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
.
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
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
<gtk-widget>
)Creates a new empty
<gtk-combo-box>
.
- ret
- A new
<gtk-combo-box>
.Since 2.4
<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
<gtk-combo-box>
) ⇒ (ret int
)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
<gtk-combo-box>
) (width int
)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
<gtk-combo-box>
) ⇒ (ret int
)Returns the column with row span information for combo-box.
- combo-box
- A
<gtk-combo-box>
.- ret
- the row span column.
Since 2.6
<gtk-combo-box>
) (row_span int
)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
<gtk-combo-box>
) ⇒ (ret int
)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
<gtk-combo-box>
) (index_ int
)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
<gtk-combo-box>
) (iter <gtk-tree-iter>
) ⇒ (ret bool
)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 setSince 2.4
<gtk-combo-box>
) (iter <gtk-tree-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
<gtk-combo-box>
) ⇒ (ret <gtk-tree-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
<gtk-combo-box>
) (model <gtk-tree-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
<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
andgtk-combo-box-remove-text
.
- ret
- A new text combo box.
Since 2.4
<gtk-combo-box>
) (text mchars
)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 usinggtk-combo-box-new-text
.- text
- A string.
Since 2.4
<gtk-combo-box>
) (position int
) (text mchars
)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 usinggtk-combo-box-new-text
.- position
- An index to insert text.
- text
- A string.
Since 2.4
<gtk-combo-box>
) (text mchars
)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 withgtk-combo-box-new-text
.- text
- A string.
Since 2.4
<gtk-combo-box>
) (position int
)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 withgtk-combo-box-new-text
.- position
- Index of the item to remove.
Since 2.4
<gtk-combo-box>
) ⇒ (ret mchars
)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 withgtk-combo-box-new-text
and with<gtk-combo-box-entry>
s.
- combo-box
- A
<gtk-combo-box>
constructed withgtk-combo-box-new-text
.- ret
- a newly allocated string containing the currently active text.
Since 2.6
<gtk-combo-box>
)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
<gtk-combo-box>
)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
<gtk-combo-box>
) ⇒ (ret <atk-object>
)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
<gtk-combo-box>
) (add_tearoffs bool
)Sets whether the popup menu should have a tearoff menu item.
- combo-box
- a
<gtk-combo-box>
- add-tearoffs
- ‘
#t
’ to add tearoff menu itemsSince 2.6
<gtk-combo-box>
) ⇒ (ret bool
)Gets the current value of the :add-tearoffs property.
- combo-box
- a
<gtk-combo-box>
- ret
- the current value of the :add-tearoffs property.
<gtk-combo-box>
) (title mchars
)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
<gtk-combo-box>
) ⇒ (ret mchars
)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
<gtk-combo-box>
) (focus_on_click bool
)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
<gtk-combo-box>
) ⇒ (ret bool
)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