Davyd ([info]davyd) wrote,
@ 2008-03-28 15:11:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
dear lazyweb (using GTK+ theme colours in custom widgets)
Dear Lazyweb,

I've never quite worked out which GtkStyle element should be used where. I'm hoping that someone can clear some things up for me.
For example, in this new widget I'm writing, I'm trying to set the background colour to be the default window background colour, which I had thought to be self->style->bg[GTK_STATE_NORMAL], but clearly it is not.

What colour should I be using instead?

Update: it turns out the trick is to set the background in the ::realize handler.


(Post a new comment)

Background colour PITA
(Anonymous)
2008-03-28 07:13 am UTC (link)
I had this exact same problem, I expect that your widget is inside of a notebook (or similar), so something like this works for me...


---
g->notebook = g->main_widget;
while (g_ascii_strncasecmp(gtk_widget_get_name(g->notebook),
"GtkNotebook", 12)) {
g->notebook = gtk_widget_get_parent(g->notebook);
if (g->notebook == NULL) {
// Fall back to using the main_widget for styles
g->notebook = g->main_widget;
break;
}
}
GtkStyle *style = gtk_widget_get_style (g->notebook);
gdk_cairo_set_source_color (tmp_cr, &style->bg[GTK_STATE_NORMAL]);
---

The problem is that there are slight variations in many themes for various widgets, these variations are barely noticable at times...

Btw, I wrote this code from gnome-system-monitor, it has since been updated by Benoit to use gtkmm instead of C.

Karl,

(Reply to this)


(Anonymous)
2008-03-28 09:50 am UTC (link)
You basically want the widget to be transparent, so just use the style from the parent widget. gtk_style_apply_default_background() may also do the trick.

-thos

(Reply to this)(Thread)


[info]davyd
2008-03-28 09:58 am UTC (link)
The manual entry for gtk_style_apply_default_background() is not as useful as one might like.

(Reply to this)(Parent)


(Anonymous)
2008-03-28 04:03 pm UTC (link)
Hi,

How about

GtkStyle *style = gtk_rc_get_style(widget);
gtk_widget_modify_bg(widget,GTK_STATE_NORMAL,&(style->bg[GTK_STATE_NORMAL]));

or you could override GtkWidget's expose_event methode within which widget->style seems to hold the correct colors.

Better solutions ?

(Reply to this)

How did you create your style?
[info]federico
2008-03-28 08:15 pm UTC (link)
When realizing your widget, how did you create its style?

(Reply to this)(Thread)

Re: How did you create your style?
[info]davyd
2008-03-28 11:56 pm UTC (link)
So the widget it inherits is actually a GooCanvas (it's a useful base from which to implement a widget). I'm setting the background by simply using its "background-rgb" property.

goo_canvas_realize

(Reply to this)(Parent)

style color viewer
(Anonymous)
2008-03-29 01:51 pm UTC (link)
in the hope that its useful - I wrote a small style color viewer:
http://bugzilla.gnome.org/show_bug.cgi?id=524966

Stefan

(Reply to this)


Create an Account
Forgot your login?
Login w/ OpenID
English • Español • Deutsch • Русский…