ProgramacionGTKenC/CapituloV

De Wiki GNOME Chile
Saltar a: navegación, buscar

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();
}
Herramientas personales
Espacios de nombres

Variantes
Acciones
Navegación
Herramientas