Re: Changing the font changes background color!
- From: Owen Taylor <otaylor redhat com>
- To: Eric Plaster <plaster imageman com>
- Cc: "gtk-list redhat com" <gtk-list redhat com>
- Subject: Re: Changing the font changes background color!
- Date: 15 Aug 1999 10:18:40 -0400
Eric Plaster <plaster@imageman.com> writes:
> Hello,
> I'm having a problem changing the font and the text color for a
> widget. I would like to be able to have
> some items in a clist to be bold and some to not be. I tried this:
>
> void ChangeFont(GtkWidget *widget)
> {
> GtkStyle *style;
>
> style = gtk_widget_get_style(widget);
> _font = gdk_font_load(_ConstructFont());
> if(_font != NULL) {
> style->font = _font;
> for(int i=0; i<5; i++) {
> style->text[i] = TextColor(); // TextColor returns a GtkColor *
>
> }
> gtk_widget_set_style(widget, style);
> gtk_widget_ensure_style(widget);
> }
> }
>
> But it screws up the background and foreground colors that are set with
> the gtk themes. I even tried to
> just set the style in the widget directly (just the stuff that I want
> changed) and nothing happened. What am
> I missing?
you need something more like (untested, but, I think,
closer to working):
void ChangeFont(GtkWidget *widget)
{
GtkStyle *style;
_font = gdk_font_load(_ConstructFont());
if(_font != NULL)
{
gtk_widget_ensure_style (widget);
style = gtk_style_copy (gtk_widget_get_style(widget));
if (style->font)
gtk_font_unref (style->font);
style->font = _font;
for(int i=0; i<5; i++)
style->text[i] = TextColor(); // TextColor returns a GtkColor *
gtk_widget_set_style(widget, style);
}
}
Note that unless your widget is already added into
the widget heirarchy, it could (in theory) not get
the right style from the theme, because the widget
does not yet have its full pathname, and a theme
could theoretically do:
widget "GtkWindow.*.GtkLabel" style "label1"
widget "GnomeDialog.*.GtkLabel" style "label2"
Note also that gtk_widget_modify_style() is
supposed to be a better way of doing these things,
but it is buggy right now, so I'm not going to
bother describing how to use it.
[ The problem with the above is that it doesn't
react to theme _changes_ properly ]
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]