Re: ComboBox submenus



Hi Tadej,
1) you were right, titles in combobox submenus can be easily removed calling gtk_cell_layout_set_cell_data_func, as demonstrated in gtk-demo.

2) I also found that the width of submenus can be easily set, with the property "width-chars", applied to the cell_renderer.

I posted the relevant code below, in case it helps someone else.

Many thanks to Tadej Borovšak and Matthias Clasen, for clarifying this,
Carlos

renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", 0, NULL);
/* set the same width in chars for all submenus */
g_object_set (renderer, "width-chars", 12, NULL);

/* hide the submenu titles */
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
renderer, hide_titles, NULL, NULL);

void hide_titles (GtkCellLayout *layout, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, void *data)
{
int sensitive;

sensitive = TRUE;
if (gtk_tree_model_iter_has_child (model, iter) == TRUE)
 sensitive = FALSE;

g_object_set (renderer, "sensitive", sensitive, NULL);
}






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