GTK gossip: gtkcombobox

Source: Internet
Author: User
Tags gtk

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:

  • Gtk_combo_box_demo.c
#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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.