库存GTK按钮不显示?

时间:2016-09-09 10:30:04

标签: c gtk codeblocks

我在CodeBlocks(Windows 7)中使用GTK,我尝试创建gtk_button_new_from_stock所以我使用了这段代码:

#include <stdlib.h>
#include <gtk.h>

int main(int argc, char **argv)
{
    GtkWidget* Window=NULL ,  *Btn = NULL;

    gtk_init(&argc, &argv);
    Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(Window), 320 ,200);


    g_signal_connect(G_OBJECT(Window), "destroy", G_CALLBACK(gtk_main_quit),    NULL);


    Btn = gtk_button_new_from_stock(GTK_STOCK_QUIT);
    g_signal_connect(G_OBJECT(Btn), "clicked", G_CALLBACK(gtk_main_quit), NULL);
    gtk_container_add(GTK_CONTAINER(Window), Btn);

    gtk_widget_show_all(Window);

    gtk_main();
    return EXIT_SUCCESS;
}

问题是:此按钮不显示图像。有没有其他方法可以创建一个带有图像的按钮?

1 个答案:

答案 0 :(得分:0)

使用GTK_ICON_SIZE_BUTTON

设置图像的大小
GtkWidget *button;
GtkWidget *image;

button = gtk_button_new();
image = gtk_image_new_from_stock(GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON);
gtk_button_set_image(GTK_BUTTON(button), image);