ProgramacionGTKenC/CapituloV
De Wiki GNOME Chile
(Diferencias entre revisiones)
(→Tooltip) |
(→Tooltip) |
||
Línea 19: | Línea 19: | ||
GtkWidget *ventana; | GtkWidget *ventana; | ||
GtkWidget *boton; | GtkWidget *boton; | ||
+ | GtkTooltips *tooltip; | ||
+ | |||
+ | gtk_init (&argc, &argv); | ||
+ | |||
+ | ventana = gtk_window_new (GTK_WINDOW_TOPLEVEL); | ||
+ | boton = gtk_button_new_with_label ("Click me!"); | ||
+ | tooltip = gtk_tooltips_new (); | ||
+ | |||
+ | gtk_tooltips_set_tip (tooltip, | ||
+ | boton, | ||
+ | "Por favor, haz click!", | ||
+ | NULL); | ||
+ | |||
+ | gtk_container_add ((GtkContainer *) ventana, boton); | ||
+ | gtk_widget_show_all (ventana); | ||
+ | gtk_main(); | ||
+ | }</pre> | ||
+ | |||
+ | Al desplazar el mouse sobre el boton, se vera algo así: | ||
+ | |||
+ | [[Imagen:Tooltip2.jpg]] | ||
+ | |||
+ | Una de las cosas interesantes del control de tooltip es que es reciclable. Es decir, se puede usar el mismo tooltip para distintos controles. | ||
+ | |||
+ | <pre>#include <gtk/gtk.h> | ||
+ | |||
+ | int main (int argc, char * argv[]) | ||
+ | { | ||
+ | GtkWidget *ventana; | ||
+ | GtkWidget *caja; | ||
+ | GtkWidget *boton1; | ||
+ | GtkWidget *boton2; | ||
GtkTooltips *tooltip; | GtkTooltips *tooltip; | ||
Línea 24: | Línea 56: | ||
ventana = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ventana = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
− | + | boton1 = gtk_button_new_with_label("Click me first!"); | |
+ | boton2 = gtk_button_new_with_label("Click me next!"); | ||
+ | caja = gtk_hbox_new(TRUE, 3); | ||
tooltip = gtk_tooltips_new(); | tooltip = gtk_tooltips_new(); | ||
− | gtk_tooltips_set_tip(tooltip, | + | gtk_box_pack_start ((GtkBox *) caja, |
− | + | boton1, | |
+ | TRUE, | ||
+ | TRUE, | ||
+ | 2); | ||
+ | |||
+ | gtk_box_pack_start ((GtkBox *) caja, | ||
+ | boton2, | ||
+ | TRUE, | ||
+ | TRUE, | ||
+ | 2); | ||
+ | |||
+ | |||
+ | gtk_tooltips_set_tip (tooltip, | ||
+ | boton1, | ||
"Por favor, haz click!", | "Por favor, haz click!", | ||
NULL); | NULL); | ||
− | gtk_container_add((GtkContainer *) ventana, | + | gtk_tooltips_set_tip (tooltip, |
+ | boton2, | ||
+ | "Y despuez, click aca!", | ||
+ | NULL); | ||
+ | |||
+ | gtk_container_add((GtkContainer *) ventana, caja); | ||
gtk_widget_show_all(ventana); | gtk_widget_show_all(ventana); | ||
gtk_main(); | gtk_main(); | ||
}</pre> | }</pre> | ||
− | |||
− | |||
− | |||
− |
Revisión de 17:04 8 ago 2006
Widgets Misceláneos
Ahora veremos algunos widgets bastante interesantes.
Tooltip
Un tooltip es una indicación de texto cuando se desplaza el mouse sobre algun control, o alguna zona de pantalla.
Error al crear miniatura: No se ha podido guardar la miniatura
El funcionamiento es muy simple. En vez de crear una variable GtkWidget, se crea una variable de tipo GtkTooltips
. Luego, se puede asociar algun texto con respecto a un control en particular.
Veamos el ejemplo.
#include <gtk/gtk.h> int main (int argc, char * argv[]) { GtkWidget *ventana; GtkWidget *boton; GtkTooltips *tooltip; gtk_init (&argc, &argv); ventana = gtk_window_new (GTK_WINDOW_TOPLEVEL); boton = gtk_button_new_with_label ("Click me!"); tooltip = gtk_tooltips_new (); gtk_tooltips_set_tip (tooltip, boton, "Por favor, haz click!", NULL); gtk_container_add ((GtkContainer *) ventana, boton); gtk_widget_show_all (ventana); gtk_main(); }
Al desplazar el mouse sobre el boton, se vera algo así:
Error al crear miniatura: No se ha podido guardar la miniatura
Una de las cosas interesantes del control de tooltip es que es reciclable. Es decir, se puede usar el mismo tooltip para distintos controles.
#include <gtk/gtk.h> int main (int argc, char * argv[]) { GtkWidget *ventana; GtkWidget *caja; GtkWidget *boton1; GtkWidget *boton2; GtkTooltips *tooltip; gtk_init(&argc, &argv); ventana = gtk_window_new(GTK_WINDOW_TOPLEVEL); boton1 = gtk_button_new_with_label("Click me first!"); boton2 = gtk_button_new_with_label("Click me next!"); caja = gtk_hbox_new(TRUE, 3); tooltip = gtk_tooltips_new(); gtk_box_pack_start ((GtkBox *) caja, boton1, TRUE, TRUE, 2); gtk_box_pack_start ((GtkBox *) caja, boton2, TRUE, TRUE, 2); gtk_tooltips_set_tip (tooltip, boton1, "Por favor, haz click!", NULL); gtk_tooltips_set_tip (tooltip, boton2, "Y despuez, click aca!", NULL); gtk_container_add((GtkContainer *) ventana, caja); gtk_widget_show_all(ventana); gtk_main(); }