Gtkcombobox
You can create a drop-down list for users to select the category. The Model-View Mode is available in gtkcombobox, which provides a rich category type and table mode, however, this also improves the degree of parallelism during program preparation. For this reason, gtkcombobox provides gtk_combo_box_new_text () to create
I
Gtkcombobox, a commonly used drop-down list function. If you want to set the text targets in the drop-down list, you can use gtk_combo_box_append_text
(),
Gtk_combo_box_insert_text (), gtk_combo_box_prepend_text (),
Gtk_combo_box_remove_text () and gtk_combo_box_get_active_text.
The following program is a simple display. In practice, only the gtkcombobox selected by the text is used as the starting part of the gtkcombobox, the selected text is displayed in the gtklabel below:
#include <gtk/gtk.h>
gboolean combo_changed(GtkComboBox *comboBox, GtkLabel *label) {
gchar *active = gtk_combo_box_get_active_text(comboBox);
gtk_label_set_text(label, active);
}
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *comboBox;
GtkWidget *label;
GtkWidget *vbox;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GtkComboBox");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 50);
comboBox = gtk_combo_box_new_text();
gtk_combo_box_append_text(GTK_COMBO_BOX(comboBox), "caterpillar");
gtk_combo_box_append_text(GTK_COMBO_BOX(comboBox), "momor");
gtk_combo_box_append_text(GTK_COMBO_BOX(comboBox), "hamimi");
gtk_combo_box_append_text(GTK_COMBO_BOX(comboBox), "bush");
gtk_combo_box_set_active(GTK_COMBO_BOX(comboBox), 0);
label = gtk_label_new("caterpillar");
vbox = gtk_vbox_new(TRUE, 5);
gtk_box_pack_start(GTK_BOX(vbox), comboBox, TRUE, TRUE, 5);
gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 5);
gtk_container_add(GTK_CONTAINER(window), vbox);
g_signal_connect(GTK_OBJECT(comboBox), "changed",
G_CALLBACK(combo_changed), label);
g_signal_connect(GTK_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
The following figure shows the details of a primary row: