Re: How to use a combo box with a cell renderer



Oh my bad this doesn't segfault at all and works perfectly:

//compile with...
//gcc combo_test.c -o ct `pkg-config --cflags --libs gtk+-2.0` && ./ct
#include <gtk/gtk.h>
int main(int argc, char *argv[]){
  GtkWidget *window, *combo;
  GtkListStore *store;
  GtkTreeIter iter;
  GtkCellRenderer *renderer;

  gtk_init (&argc, &argv);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  store = gtk_list_store_new(1, G_TYPE_STRING);
  gtk_list_store_append(store, &iter);
  gtk_list_store_set(store, &iter, 0, "Why can't I see this text at all", -1);
  combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
  renderer = gtk_cell_renderer_text_new();
  gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE);
  gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), renderer,
"text", 0);

  gtk_container_add(GTK_CONTAINER(window), combo);
  gtk_widget_show_all(window);
  gtk_main();
  return 0;
}

The issue with segfaulting happens when you call 
gtk_cell_layout_set_attributes () before you call 
gtk_cell_layout_pack_start() since the attributes effect the renderer I guess
this makes sense maybe... in anycase I'm content calling them in order that
works:)

Thanks everybody.
                                                                -Hudson Lee



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