Top | ![]() |
![]() |
![]() |
![]() |
A GtkComboBox is a widget that allows the user to choose from a list of valid choices. The GtkComboBox displays the selected choice. When activated, the GtkComboBox 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 Windows-style combo box.
The GtkComboBox 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 GtkComboBox implements the GtkCellLayout 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.
To allow the user to enter values not in the model, the “has-entry”
property allows the GtkComboBox to contain a GtkEntry. This entry
can be accessed by calling gtk_bin_get_child()
on the combo box.
For a simple list of textual choices, the model-view API of GtkComboBox can be a bit overwhelming. In this case, GtkComboBoxText offers a simple alternative. Both GtkComboBox and GtkComboBoxText can contain an entry.
1 2 3 4 5 6 7 |
combobox ├── box.linked │ ╰── button.combo │ ╰── box │ ├── cellview │ ╰── arrow ╰── window.popup |
A normal combobox contains a box with the .linked class, a button with the .combo class and inside those buttons, there are a cellview and an arrow.
1 2 3 4 5 6 7 |
combobox ├── box.linked │ ├── entry.combo │ ╰── button.combo │ ╰── box │ ╰── arrow ╰── window.popup |
A GtkComboBox with an entry has a single CSS node with name combobox. It contains a box with the .linked class. That box contains an entry and a button, both with the .combo class added. The button also contains another node with name arrow.
GtkWidget *
gtk_combo_box_new (void
);
Creates a new empty GtkComboBox.
Since: 2.4
GtkWidget *
gtk_combo_box_new_with_entry (void
);
Creates a new empty GtkComboBox with an entry.
Since: 2.24
GtkWidget *
gtk_combo_box_new_with_model (GtkTreeModel *model
);
Creates a new GtkComboBox with the model initialized to model
.
Since: 2.4
GtkWidget *
gtk_combo_box_new_with_model_and_entry
(GtkTreeModel *model
);
Creates a new empty GtkComboBox with an entry
and with the model initialized to model
.
Since: 2.24
gint
gtk_combo_box_get_wrap_width (GtkComboBox *combo_box
);
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.
Since: 2.6
void gtk_combo_box_set_wrap_width (GtkComboBox *combo_box
,gint 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: 2.4
gint
gtk_combo_box_get_row_span_column (GtkComboBox *combo_box
);
Returns the column with row span information for combo_box
.
Since: 2.6
void gtk_combo_box_set_row_span_column (GtkComboBox *combo_box
,gint 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: 2.4
gint
gtk_combo_box_get_column_span_column (GtkComboBox *combo_box
);
Returns the column with column span information for combo_box
.
Since: 2.6
void gtk_combo_box_set_column_span_column (GtkComboBox *combo_box
,gint 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: 2.4
gint
gtk_combo_box_get_active (GtkComboBox *combo_box
);
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 GtkTreePath of the active item.
An integer which is the index of the currently active item, or -1 if there’s no active item.
Since: 2.4
void gtk_combo_box_set_active (GtkComboBox *combo_box
,gint index_
);
Sets the active item of combo_box
to be the item at index
.
combo_box |
||
index_ |
An index in the model passed during construction, or -1 to have no active item |
Since: 2.4
gboolean gtk_combo_box_get_active_iter (GtkComboBox *combo_box
,GtkTreeIter *iter
);
Sets iter
to point to the current active item, if it exists.
Since: 2.4
void gtk_combo_box_set_active_iter (GtkComboBox *combo_box
,GtkTreeIter *iter
);
Sets the current active item to be the one referenced by iter
, or
unsets the active item if iter
is NULL
.
Since: 2.4
gint
gtk_combo_box_get_id_column (GtkComboBox *combo_box
);
Returns the column which combo_box
is using to get string IDs
for values from.
Since: 3.0
void gtk_combo_box_set_id_column (GtkComboBox *combo_box
,gint id_column
);
Sets the model column which combo_box
should use to get string IDs
for values from. The column id_column
in the model of combo_box
must be of type G_TYPE_STRING
.
Since: 3.0
const gchar *
gtk_combo_box_get_active_id (GtkComboBox *combo_box
);
Returns the ID of the active row of combo_box
. This value is taken
from the active row and the column specified by the “id-column”
property of combo_box
(see gtk_combo_box_set_id_column()
).
The returned value is an interned string which means that you can compare the pointer by value to other interned strings and that you must not free it.
If the “id-column” property of combo_box
is not set, or if
no row is active, or if the active row has a NULL
ID value, then NULL
is returned.
Since: 3.0
gboolean gtk_combo_box_set_active_id (GtkComboBox *combo_box
,const gchar *active_id
);
Changes the active row of combo_box
to the one that has an ID equal to
active_id
, or unsets the active row if active_id
is NULL
. Rows having
a NULL
ID string cannot be made active by this function.
If the “id-column” property of combo_box
is unset or if no
row has the given ID then the function does nothing and returns FALSE
.
TRUE
if a row with a matching ID was found. If a NULL
active_id
was given to unset the active row, the function
always returns TRUE
.
Since: 3.0
GtkTreeModel *
gtk_combo_box_get_model (GtkComboBox *combo_box
);
Returns the GtkTreeModel which is acting as data source for combo_box
.
Since: 2.4
void gtk_combo_box_set_model (GtkComboBox *combo_box
,GtkTreeModel *model
);
Sets the model used by combo_box
to be model
. Will unset a previously set
model (if applicable). If model is NULL
, then it will unset the model.
Note that this function does not clear the cell renderers, you have to
call gtk_cell_layout_clear()
yourself if you need to set up different
cell renderers for the new model.
Since: 2.4
void gtk_combo_box_popup_for_device (GtkComboBox *combo_box
,GdkDevice *device
);
Pops up the menu of combo_box
. Note that currently this does not do anything
with the device, as it was previously only used for list-mode ComboBoxes,
and those were removed in GTK+ 4. However, it is retained in case similar
functionality is added back later.
Since: 3.0
void
gtk_combo_box_popup (GtkComboBox *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.
Before calling this, combo_box
must be mapped, or nothing will happen.
Since: 2.4
void
gtk_combo_box_popdown (GtkComboBox *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.
Since: 2.4
AtkObject *
gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box
);
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.
Since: 2.6
GtkTreeViewRowSeparatorFunc
gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box
);
Returns the current row separator function.
[skip]
Since: 2.6
void gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box
,GtkTreeViewRowSeparatorFunc func
,gpointer data
,GDestroyNotify destroy
);
Sets the row separator function, which is used to determine
whether a row should be drawn as a separator. If the row separator
function is NULL
, no separators are drawn. This is the default value.
Since: 2.6
void gtk_combo_box_set_button_sensitivity (GtkComboBox *combo_box
,GtkSensitivityType sensitivity
);
Sets whether the dropdown button of the combo box should be
always sensitive (GTK_SENSITIVITY_ON
), never sensitive (GTK_SENSITIVITY_OFF
)
or only if there is at least one item to display (GTK_SENSITIVITY_AUTO
).
Since: 2.14
GtkSensitivityType
gtk_combo_box_get_button_sensitivity (GtkComboBox *combo_box
);
Returns whether the combo box sets the dropdown button sensitive or not when there are no items in the model.
GTK_SENSITIVITY_ON
if the dropdown button
is sensitive when the model is empty, GTK_SENSITIVITY_OFF
if the button is always insensitive or
GTK_SENSITIVITY_AUTO
if it is only sensitive as long as
the model has one item to be selected.
Since: 2.14
gboolean
gtk_combo_box_get_has_entry (GtkComboBox *combo_box
);
Returns whether the combo box has an entry.
Since: 2.24
void gtk_combo_box_set_entry_text_column (GtkComboBox *combo_box
,gint text_column
);
Sets the model column which combo_box
should use to get strings from
to be text_column
. The column text_column
in the model of combo_box
must be of type G_TYPE_STRING
.
This is only relevant if combo_box
has been created with
“has-entry” as TRUE
.
Since: 2.24
gint
gtk_combo_box_get_entry_text_column (GtkComboBox *combo_box
);
Returns the column which combo_box
is using to get the strings
from to display in the internal entry.
Since: 2.24
void gtk_combo_box_set_popup_fixed_width (GtkComboBox *combo_box
,gboolean fixed
);
Specifies whether the popup’s width should be a fixed width matching the allocated width of the combo box.
Since: 3.0
gboolean
gtk_combo_box_get_popup_fixed_width (GtkComboBox *combo_box
);
Gets whether the popup uses a fixed width matching the allocated width of the combo box.
Since: 3.0