如何使用GTK向按钮添加图像 [英] How to add an image to a button with GTK
本文介绍了如何使用GTK向按钮添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将图像添加到带有标签的按钮上,但是该图像不显示并且损坏的图像也不显示.
I am trying to add an image to a button with label, but the image doesn't show and the broken image doesn't display either.
stop_button = gtk_button_new_with_label("stop");
image = gtk_image_new_from_file ("/home/cendit/Escritorio/index.jpeg");
gtk_button_set_image (GTK_BUTTON(stop_button),image);
我尝试了其他路径"file:///home/cendit/Escritorio/index.jpeg",但未成功.
I tried a different path "file:///home/cendit/Escritorio/index.jpeg" but it was not successful.
推荐答案
这是您需要做的
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);
这篇关于如何使用GTK向按钮添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文