Populating A Combo Box With Integers In Hex

2013-12-07 Thread Tristian Celestin
I have a GtkListStore that contains 4 columns of unsigned integers 
(G_TYPE_UINT). I would like to display the second column of integers in a 
GtkComboBoxText widget, and I would like the integers to be displayed in Base 
12. 

Based on the GTK 3.10 documentation, the following will populate the combo box 
for columns of G_TYPE_STRING:

gtk_combo_box_set_model(GTK_COMBO_BOX(self-priv-comboboxtext1),
    GTK_TREE_MODEL(device_store));
gtk_combo_box_set_id_column(GTK_COMBO_BOX(self-priv-comboboxtext1), 1);

Is my only solution to add another column to the list store containing strings 
of hex-converted integers? Ideally, I'd be able to tell the combo box how to 
format a string it displays for each unsigned integer in the model. 
  
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Populating A Combo Box With Integers In Hex

2013-12-07 Thread David Nečas
On Sat, Dec 07, 2013 at 05:54:23PM +, Tristian Celestin wrote:
 I have a GtkListStore that contains 4 columns of unsigned integers
 (G_TYPE_UINT). I would like to display the second column of integers
 in a GtkComboBoxText widget, and I would like the integers to be
 displayed in Base 12. 

I would stop here and use normal GtkComboBox with a cell data function
(gtk_cell_layout_set_cell_data_func()) such as

static void
render_base12(GtkTreeViewColumn *column,
  GtkCellRenderer *renderer,
  GtkTreeModel *model,
  GtkTreeIter *iter,
  gpointer data)
{
guint value;
gtk_tree_model_get(model, iter, 1, value, -1);
/* format the value here in base 12 */
g_object_set(renderer, text, formatted_value, NULL);
}

It may be possible to do this with GtkComboBoxText too.  I don't know.
If I want something non-default I just use the real thing instead of
studying what is and what isn't allowed with GtkComboBoxText.

Regards,

Yeti

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list