Lorhan
Lorhan

Reputation: 13

How can I get a string from a gtk_combo_box item that was selected?

How can I get the string from a gtk_combo_box item that was selected?

For example, if a person selects fullscreen, I need to get the fullscreen string.

    GtkWidget *widget;
    GtkListStore *liststore;
    GtkCellRenderer *column;
    liststore = gtk_list_store_new(1, G_TYPE_STRING);
    widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(liststore));
    gtk_list_store_insert_with_values(liststore, NULL, -1,0, " ",-1);
    gtk_list_store_insert_with_values(liststore, NULL, -1,0, "fullscreen",-1);
    gtk_list_store_insert_with_values(liststore, NULL, -1,0, "windowed",-1);
    gtk_list_store_insert_with_values(liststore, NULL, -1,0, "640 x 480",-1);
    gtk_list_store_insert_with_values(liststore, NULL, -1,0, "720 x 480",-1);
    gtk_list_store_insert_with_values(liststore, NULL, -1,0, "1280 x 720",-1);
    gtk_list_store_insert_with_values(liststore, NULL, -1,0, "1920 x 1080",-1);
    gtk_list_store_insert_with_values(liststore, NULL, -1,0, "3840 x 2160",-1);
    gtk_list_store_insert_with_values(liststore, NULL, -1,0, "7680 x 4320",-1);
    column = gtk_cell_renderer_text_new();
    gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0);
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), column, TRUE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), column,"text", 0,NULL);
    g_signal_connect (widget, "changed", G_CALLBACK (set_screen_mode),NULL);

Upvotes: 1

Views: 687

Answers (1)

oldtechaa
oldtechaa

Reputation: 1524

For a simple text-only list like this, use a GtkComboBoxText and get the text with get_active_text.

Upvotes: 2

Related Questions