Re: Menu with stuff in multiple columns?



On 11/5/07, Reed Hedges <reed mobilerobots com> wrote:

I have a large list of small names I want to display in a popup menu.  Is there
any way to tell GTK to allow more than one column, rather than having the popup
menu fill the screen from top to bottom?

Yes there is. For example, I've made once some calendar like thing
where you can select a month from a 2 columns menu.

Untested code, but should work:

  GtkWidget *combo;
  GtkListStore *store;
  GtkTreeIter iter;
  GtkCellRenderer *renderer;
  int i;
  char**p;
  char*months[]={"jan","jul","feb","aug","mar","sep","apr","oct","may",
                  "nov","jun","dec",NULL};

  store=gtk_list_store_new(1,G_TYPE_STRING);
  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_set_attributes(GTK_CELL_LAYOUT(combo),renderer,
                                 "text",0,NULL);
  gtk_combo_box_set_wrap_width (GTK_COMBO_BOX (combo),2);

  for(p=months;*p;p++){
    gtk_list_store_append(store,&iter);
    gtk_list_store_set(store,&iter,0,*p,-1);
  }

  gtk_combo_box_set_active(GTK_COMBO_BOX(combo),0);
  g_object_unref(store);

Good luck.
CH



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