Re: GtkComboBox, models and views



Diego Zuccato wrote:

Hello all.

I'm trying to use the new combo box w/ models to reduce screen
cluttering while porting an "old" app that used a plain treeview.
I already connected the model to the combo, but how can I replace:

// cbx is the combo box, zone1 is the model, v is the treeview
gtk_combo_box_set_model(cbx, zone1);
v=GTK_TREE_VIEW(gtk_combo_box????()); // How can I get the view?
//converted gtk_tree_view_set_model(v, zone1);
c=gtk_tree_view_column_new_with_attributes(NULL, rt, "text", ZONE_DSC,
NULL);
gtk_tree_view_append_column(v, c);
// Are these needed?
sel=gtk_tree_view_get_selection(v);
gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);

You can create your GtkTreeModel as if it was for a GtkTreeView,

But, don't use GtkTreeViewColumn, but GtkCellLayout.
GtkCellRenderer *renderer = NULL;
GtkTreeModel *tree_model = NULL;
GtkComboBox *comboBox = NULL;
comboBox = gtk_combo_box_new ();
   if (comboBox) {
tree_model = GTK_TREE_MODEL (gtk_list_store_new (3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING));
       if (tree_model) {

          renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comboBox), renderer, FALSE); gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (comboBox), renderer, "text", 0);

           renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comboBox), renderer, FALSE); gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (comboBox), renderer, "text", 2);

gtk_combo_box_set_model (GTK_COMBO_BOX (comboBox), GTK_TREE_MODEL(tree_model));
       }
   }





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