且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用GTK向按钮添加图像

更新时间:2023-12-04 10:27:04

这是您需要做的

GtkImage *imagen_pantalla_completa;
GtkWidget *pantalla_completa;

pantalla_completa = gtk_button_new_with_label("");                                                  
imagen_pantalla_completa = (GtkImage *)gtk_image_new_from_file("/home/user..."); 
gtk_button_set_image (GTK_BUTTON(pantalla_completa),(GtkWidget *)imagen_pantalla_completa); 

您需要添加它才能显示图像

You need to add this to display the image

GtkSettings *default_settings = gtk_settings_get_default();
g_object_set(default_settings, "gtk-button-images", TRUE, NULL);