开发者

GtkButton just shows text but no image

I have a GtkButton inside a GtkHButtonBox that doesn't show the i开发者_Go百科mage I'm adding to it. It just shows the text. Here's the code:

GtkImage *image = (GtkImage *) gtk_image_new_from_file("Gateway-LT21-netbook-2-540x359");
GtkButton *button = (GtkButton *) gtk_button_new_with_label("test");
gtk_button_set_image(button, (GtkWidget *) image);

Is there something I'm missing?


Make sure that the "gtk-button-images" setting is set to true.

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

Note: This should follow the construction of the first window (and of course precede the main loop).

If I'm not mistaken, this is a rather recent change in Gnome - for some reason, they decided for icons not to appear on buttons as default (this also seems to apply to the standard MS Windows theme).


Try this:

gtk_widget_show(GTK_WIDGET(image))


Apparently, at least in GTK+ 3 there is a function called gtk_button_set_always_show_image(), which is supposed to enable an image for a particular button regardless of global settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜