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