Re: Tool tip colors

Bob Stafford <> writes:

> I've got one question and one bug report (I think).
> Firstly the bug report (I assume that the people who maintain GTK read
> this list, if there is a better place to report bugs please let me
> know).
> In the file gtktooltips.c at around line 401 is the following piece of
> code
>   if (background != NULL)                    -- I think this should be
> foreground
>     tooltips->foreground = foreground;
>   if (foreground != NULL)                    -- and this should be
> background.
>     tooltips->background = background;

Well, yes, but see below.
> Next the question that led me to be looking at the code in the first
> place.
> Can anybody tell me why the tooltip in the following test program does
> not have  black text on a blue background. I'm running gtk 1.2.6 on
> RH 6.0.

If you look around a bit more at the code, you'll find that
the values set by gtk_tooltips_set_colors() are completely
unused. They haven't worked for at least a year, if they
were ever functional.

First, the color of the tooltips is not something a program should
be changing under almost any circumstances. The color of the
tooltips is a perogative of the user / theme designer. Yes,
the default gray isn't very nice; the GTK+ packages we distribute
at Red Hat include the following in $sysconfdir/gtk/gtkrc.

style "gtk-tooltips-style" {
  bg[NORMAL] = "#ffffc0"

widget "gtk-tooltips" style "gtk-tooltips-style"

If you wanted to do something different in a program,
it could either parse its own gtkrc file, or set up the
style explicitely.

This would look something like:

set_bg (GtkWidget *widget, gushort red, gushort green, gushort blue)
	GtkRcStyle *rc_style = gtk_rc_style_new();

	rc_style->color_flags[GTK_STATE_NORMAL] = GTK_RC_BG;
	rc_style->bg[GTK_STATE_NORMAL].red = red;
	rc_style->bg[GTK_STATE_NORMAL].green = green;
	rc_style->bg[GTK_STATE_NORMAL].blue = blue;

	gtk_widget_modify_style (widget, rc_style);
        gtk_rc_style_unref (rc_style);

GtkTooltips *tips = gtk_tooltips_new ();
gtk_tooltips_force_window (tips);
set_bg (tips->tip_window, 0xffff, 0, 0);

[ The modify_style() call only works with GTK+ 1.2.5 or newer -
  there were bugs before that which caused difficulties; you
  could also use a call to gtk_widget_set_style() if working]
  with older GTK+ versions is important to you. ]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]