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



Hmm... I thought that was perfectly clear, ok I'll spell it out for you folks.
All I want is to be able to use a combo box with a model view. My problem
is this doesn't work because I can't get the text to show up in the items in
the combo box. Ie. I get the combo box but when I click it 
"Why can't I see this text at all" isn't there, I get a blank line.

Here is my test program again since I'm not sure anyone actually read it the 
first time. Does this program work for other people? Perhaps my gtk is messed 
up even though text based (not model) combo boxes work fine.
//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_container_add(GTK_CONTAINER(window), combo);
  gtk_widget_show_all(window);
  gtk_main();
  return 0;
}

Okay in response to Bob saying: "have you tried using a GtkCellRendererText
object instead of the GtkCellRenderer object? The initialization function is:
GtkCellRenderer* gtk_cell_renderer_text_new (void);"

Um Bob I don't get it don't I call that exact function in my code above?
Am I missing something?

And yes I have gtk installed (2.4 as I said before) and gtk-demo lacks combo 
boxes so I fail to see how it would help :) Of course the fact that I posted
a fully functional program which demonstates my problem with instructions to 
compile it should have been a hint to me having gtk installed but I suppose if 
you don't read the rest of the email where I say I'm using gtk 2.4 it's 
understanable how such subltes can be lost :)

Being new to gtk I'm not sure what I'm doing wrong but the same model with 
a TreeView seems to work I just can't get combo boxes working with models. 
And I'm on the mailing list now :)



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