GTK gossip: gtkentrycompletion

Source: Internet
Author: User
Tags gtk

Previously viewed

Gtkentry


Examples are mainly used for text input by the user. You can use gtkentrycompletion to enable the gtkentry notebook to automatically complete the function. This requires the use of gtkliststore and gtktreeiter, these two types are different in

Gtkcombobox
And gtkliststore



Once introduced, as long as you use gtkentry,

When using gtkliststore and gtktreeiter to perform auto-completion, it is not a difficult task.
.

The following example shows examples:

  • Gtk_entrycompletion_demo.c
# Include <GTK/GTK. h>

Int main (INT argc, char * argv []) {
Gtkwidget * window;
Gtkwidget * vbox;
Gtkwidget * label;
Gtkwidget * entry;
Gtkentrycompletion * completion;
Gtkliststore * store;
Gtktreeiter ITER;
Int I;

// As a marker prompt for the auto-completion process
Gchar * topics [] = {
"C", "C ++", "Java", "jsp", "JSF", "JUnit", "JavaScript "};

Gtk_init (& argc, & argv );

Window = gtk_window_new (gtk_window_toplevel );
Gtk_window_set_title (gtk_window (window), "gtkentrycompletion ");
Gtk_window_set_default_size (gtk_window (window), 300, 50 );

// Use the gtkliststore marker to save objects
Store = gtk_list_store_new (1, g_type_string );
For (I = 0; I <7; I ++ ){
Gtk_list_store_append (store, & ITER );
Gtk_list_store_set (store, & ITER, 0, topics [I],-1 );
}

// Set gtkliststore to gtkentrycompletion
Completion = gtk_entry_completion_new ();
Gtk_entry_completion_set_model (completion, gtk_tree_model (store ));
Gtk_entry_completion_set_text_column (completion, 0 );

Label = gtk_label_new ("Please refer to technical topics ");

// Create a gtkentry
Entry = gtk_entry_new ();

// Set gtkentrycompletion
Gtk_entry_set_completion (gtk_entry (entry), completion );

Vbox = gtk_vbox_new (false, 5 );
Gtk_box_pack_start (gtk_box (vbox), label, false, false, 0 );
Gtk_box_pack_start (gtk_box (vbox), entry, false, false, 0 );
Gtk_container_add (gtk_container (window), vbox );

G_signal_connect (gtk_object (window), "Destroy ",
G_callback (gtk_main_quit), null );

Gtk_widget_show_all (window );
Gtk_main ();

Return 0;
}


The results of a line are as follows:


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.