Re: gtk_combo_box



On Thu, 2004-06-24 at 12:39, Russell Shaw wrote:
Hi,
How do i get a combo box to display the strings: "abc","def","ghi"?
The code i tried here displays a tiny box with nothing in it.
(gtk 2.4.3)


#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <gtk/gtksignal.h>
#include "xmalloc.h"
#include <string.h>

static
gboolean delete( GtkWidget *widget, GtkWidget *event, gpointer data)
{
     gtk_main_quit ();
}

gint main(gint argc, gchar *argv[])
{
     gtk_init (&argc, &argv);

     GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);

     g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(delete),NULL);

     GtkListStore *store=
         gtk_list_store_new(4,G_TYPE_UINT,G_TYPE_UINT,G_TYPE_UINT,G_TYPE_STRING);
     GtkTreeIter iter;
     gtk_list_store_append(store,&iter);
     gtk_list_store_set(store,&iter,0,1,1,1,2,0,3,"abc",-1);
     gtk_list_store_append(store,&iter);
     gtk_list_store_set(store,&iter,0,1,1,1,2,1,3,"def",-1);
     gtk_list_store_append(store,&iter);
     gtk_list_store_set(store,&iter,0,1,1,1,2,2,3,"ghi",-1);

     GtkWidget *combo=gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
     gtk_combo_box_set_row_span_column(GTK_COMBO_BOX(combo),0);
     gtk_combo_box_set_column_span_column(GTK_COMBO_BOX(combo),1);

     gtk_container_add(GTK_CONTAINER(window),combo);
     gtk_widget_show_all(window);

     gtk_main ();

     return 0;
}

You haven't added any cell renderers. Look at the testcombo.c example in
the tests directory in GTK+.

Matthias




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