Re: How to use a combo box with a cell renderer
- From: Martyn Russell <martyn russell bt com>
- To: gtk-app-devel-list gnome org
- Cc:
- Subject: Re: How to use a combo box with a cell renderer
- Date: Thu, 23 Dec 2004 08:45:48 +0000
On Wed, 2004-12-22 at 06:40 -0500, Hudson Lee wrote:
Please reply to me (spam nilmail com) directly, I'm not sure if I'm subscribed.
Okay so I'm using gtk 2.4 what am I doing wrong the following code (simple test
program) doesn't show me any text when I click the combo menu.
//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;
}
Hi,
At first I thought that it was because you hadn't associated an
attribute with the renderer (see gtk_cell_layout_set_attributes() for
more on this), but then when I add that function or use of
gtk_cell_layout_add_attribute() it Seg Faults? I would expect this to
work!
If you uncomment the #define it uses the simpler method and works
perfectly as expected.
Matthias, any clues here?
[...]
#include <gtk/gtk.h>
/*#define WORKS*/
int main(int argc, char *argv[]){
GtkWidget *window, *combo;
GtkListStore *store;
GtkTreeIter iter;
GtkCellRenderer *renderer;
GtkCellLayout *layout;
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);
#ifdef WORKS
combo = gtk_combo_box_new_text();
gtk_combo_box_set_model(GTK_COMBO_BOX(combo), GTK_TREE_MODEL(store));
#else
combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
renderer = gtk_cell_renderer_text_new();
layout = GTK_CELL_LAYOUT(combo);
gtk_cell_layout_clear (layout);
/* the following line crashes: */
/* gtk_cell_layout_set_attributes (layout, renderer, "text", 0, NULL);
*/
gtk_cell_layout_pack_start(layout, renderer, TRUE);
#endif
gtk_container_add(GTK_CONTAINER(window), combo);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
[...]
--
Regards,
Martyn
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]