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: