Created
March 30, 2023 06:56
-
-
Save angstyloop/4aa38d2fbf046c3ee555cf4941a58dce to your computer and use it in GitHub Desktop.
GTK4 tooltip example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** tooltip.c | |
* | |
* COMPILE | |
* | |
* gcc `pkg-config --cflags gtk4` -o tooltip tooltip.c `pkg-config --libs gtk4` | |
* | |
* RUN | |
* | |
* ./tooltip | |
*/ | |
#include <gtk/gtk.h> | |
// Not strictly necessary, but here for maximum portability. | |
#if GLIB_CHECK_VERSION(2, 74, 0) | |
static int app_flags = G_APPLICATION_DEFAULT_FLAGS; | |
#else | |
static int app_flags = G_APPLICATION_FLAGS_NONE; | |
#endif | |
static void activate( GtkApplication *app, gpointer user_data ) | |
{ | |
GtkWidget *window, *button; | |
window = gtk_application_window_new( app ); | |
// You can add tooltip text to any GtkWidget. I used a GtkButton. | |
// You could just as easily use a GtkLabel by itself, or a GtkBox. | |
button = gtk_button_new_with_label( "hover here" ); | |
gtk_widget_set_tooltip_text( button, "hello world" ); | |
gtk_window_set_child( GTK_WINDOW( window ), button ); | |
gtk_widget_show(window); | |
} | |
int main (int argc, char **argv) | |
{ | |
GtkApplication *app; | |
int status; | |
puts("hover over the window to see the tooltip"); | |
app = gtk_application_new ("org.gtk.example", app_flags); | |
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); | |
status = g_application_run (G_APPLICATION (app), argc, argv); | |
g_object_unref (app); | |
return status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment