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); }
相关文章推荐
- GTK+设置控件背景图片
- CocoStudio 0.2.4.0 UI编辑器下根Panel控件设置背景图片时一个BUG
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
- 设置对话框的图片背景,控件的字体及透明等,字体重叠等
- QT中几种设置控件的图片背景的方法
- 控件设置背景或图片后无法对齐
- C#学习笔记:动态设置控件的背景图片
- QT中几种设置控件的图片背景的方法
- VC中设置了对话框背景图片的情况下不能正确显示radio控件透明
- Qt添加背景图片而不影响其控件的不用代码的设置方法
- 网络图片设置为控件背景图
- QT中几种设置控件的图片背景的方法
- WPF 后台C#设置控件背景图片
- Qt中几种设置控件的图片背景的方法
- WPF 后台C#设置控件背景图片
- WPF中动态设置控件的背景图片
- 控件设置背景或图片后无法对齐
- 窗体图片背景(两种方法:设置Brush.Bitmap指向图片,别的控件也可以这样)
- RN填坑----iOS给控件设置背景图片无效