Re: GtkComboBox madness



On Wed, 2004-12-08 at 20:36 -0500, Jay Camp wrote:
I'm trying to just stick some strings in a plain old GtkComboBox that
I'm getting from Glade.  There seems to be an easier way to do this if
you're writing the code w/o Glade (using gtk_combo_box_new_text()) but
that doesn't seem possible using Glade.  (I'll be needing to stick some
other hidden data in the combobox so I need to figure out the "regular"
way anyway).

There are so many different interfaces coming into play here that it's
confusing as heck!

Here's what I have so far:

gchar *vehicle;
GtkComboBox *comboVehicles = GTK_COMBO_BOX(glade_xml_get_widget(glade,
"comboVehicles"));

GtkListStore *listVehicles = gtk_list_store_new(1, G_TYPE_STRING);
gtk_combo_box_set_model(comboVehicles, GTK_TREE_MODEL(listVehicles));

vehicle = (char*) row[2];

GtkCellRendererText *cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(comboVehicles),
GTK_CELL_RENDERER(cell), TRUE);

gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(comboVehicles),
GTK_CELL_RENDERER(cell), "text", 0);

GtkTreeIter iter;
gtk_list_store_append(listVehicles, &iter);
gtk_list_store_set(listVehicles, &iter, 0, vehicle, -1);
gtk_list_store_set(listVehicles, &iter, 0, "HELLLO", -1);

Hi,

Few things I have noticed:

        * The GtkListStore is not unreferenced with g_object_unref after
        you have finished with it.
        
        * When using glade to get a GtkComboBox, it should return the
        equivalent of gtk_combo_box_new_text () - this may depend on
        having predetermined text strings, I can't remember.  
        
        The GtkComboBox already has one cell renderer (text) so you are
        duplicating work already done by GTK.  
        
        * If you are going to completely set up your own cell layout, I
        would advise you clear the layout first with
        gtk_cell_layout_clear ().

-- 
Regards,
Martyn



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]