您的位置:首页 > 其它

GTK+设置控件背景图片

2011-07-02 14:54 267 查看
void update_widget_bg(GtkWidget *widget, const gchar *img_file)
{
GtkStyle *style;
GdkPixbuf *pixbuf;
GdkPixmap *pixmap;
gint width, height;

pixbuf = gdk_pixbuf_new_from_file(img_file, NULL);
width = gdk_pixbuf_get_width(pixbuf);
height = gdk_pixbuf_get_height(pixbuf);
pixmap = gdk_pixmap_new(NULL, width, height, 24);
gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, NULL, 0);
style = gtk_style_copy(GTK_WIDGET (widget)->style);

if (style->bg_pixmap[GTK_STATE_NORMAL])
g_object_unref(style->bg_pixmap[GTK_STATE_NORMAL]);

style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref(pixmap);
style->bg_pixmap[GTK_STATE_ACTIVE] = g_object_ref(pixmap);
style->bg_pixmap[GTK_STATE_PRELIGHT] = g_object_ref(pixmap);
style->bg_pixmap[GTK_STATE_SELECTED] = g_object_ref(pixmap);
style->bg_pixmap[GTK_STATE_INSENSITIVE] = g_object_ref(pixmap);
gtk_widget_set_style(GTK_WIDGET (widget), style);
g_object_unref(style);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: