While designing your user interface with Glade is really convenient and easy, it doesn't allow you to use custom classes as this combo here. Thanks to the MVC model in Gtk2, you still can use this class's power by using the same model as Gtk2_IndexedComboBox uses internally: Gtk2_IndexedComboBox_Model.
Glade file to use
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> <glade-interface> <widget class="GtkWindow" id="wndTest"> <property name="visible">True</property> <property name="title" translatable="yes">Gtk2_IndexedComboBox_Model test</property> <property name="type">GTK_WINDOW_TOPLEVEL</property> <property name="window_position">GTK_WIN_POS_NONE</property> <property name="modal">False</property> <property name="resizable">True</property> <property name="destroy_with_parent">False</property> <property name="decorated">True</property> <property name="skip_taskbar_hint">False</property> <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <signal name="destroy" handler="Gtk::main_quit"/> <child> <widget class="GtkComboBox" id="cmbNormal"> <property name="visible">True</property> </widget> </child> </widget> </glade-interface>
PHP code
The important thing to remember is that you need to setup your own cell renderer, and tell it which column in the model shall be displayed. Beside that, you just do the normal model-creation-and-setting via set_model().
All data manipulation methods of Gtk2_IndexedComboBox
you saw in the previous example are available in the model,
Gtk2_IndexedComboBox_Model.
Only get_active_key() and
get_active_text() cannot be used on the model,
since this doesn't know anything about selections. Retrieve
the selected GtkTreeIter by combining the
calls of get_active() and get_iter(),
and pass this iter
object to
get_key() and get_text().