I realize GTK-2 is now 'antique'. I have an old program I have to modify, and it's just too large to convert to GTK-3 for the time I have. This is the issue:
- I added a ComboBox to which I assign a ListBox with 2 columns (G_TYPE_INT and G_TYPE_STRING).
- For some reason, both columns are shown on the ComboBox, though I think the code shown below only assigns one.
void
fill_list(GtkComboBox *cbbox)
{
GtkListStore *store = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING);
GtkTreeIter iter;
GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
gtk_combo_box_set_model(cbbox, GTK_TREE_MODEL(store));
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cbbox), renderer, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cbbox), renderer,
"text", 0, NULL);
gtk_combo_box_set_entry_text_column(cbbox, 0);
gtk_list_store_append(store, &iter);
// Col 0 Col 1
gtk_list_store_set(store, &iter, 0, 0, 1, "Kind 1", -1);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, 1, 1, "Kind 2", -1);
gtk_list_store_append(store, &iter);
This is part of the function called on the 'realize' signal of the widget.
Changing ..."text", 0... to ..."text", 1... changes the second column of the
ComboBox to, as expected, the second column of the ListStore.
But, for unknown reason, I can't get rid of the first column. I've scanned the
entire project for signs of code that might influence - no luck. The interface was
generated using Glade-2.
For the last years, I've been working more from Python, so I'm suspecting there's something
I'm missing here. I even basically tested this code in Python, and had no problem there.
I'd appreciate suggestions!
question from:
https://stackoverflow.com/questions/65919175/gtk-combobox-displays-two-columns-instead-of-1-why 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…