Re: GtkStyleContext issues



On 03/07/11 17:54, Andrew Higginson wrote:
> In this callback, I then use the gtk_render_* functions, however I seem
> to have a problem.
> 
> In the example below, I am trying to render a Progressbar, however the
> rendered progressbar doesn't look like the real progressbar (in this
> case in Glade) (http://i.imgur.com/BMhdr.png)
> 
> This issue is not restricted to just ProgressBars either, it is shown in
> other widgets. For example here is the same demo with a GtkButton,
> however the difference is only shown when using the Ambiance/Radiance
> GTK3 themes, not Adawaita (http://i.imgur.com/ADNnt.png)

I figured out this problem, and so if it helps anyone the solution is
below :)

The problem was that in the Gtk CSS, the selectors the render function
should have been using were:

GtkProgressBar.trough and GtkProgressBar.activity

However because they were being run from a GtkDrawingArea, they were using:

GtkDrawingArea.trough and GtkDrawingArea.activity

To fix this, you need to change the GtkWidgetPath of the GtkStyleContext
you are using with the gtk_render* functions. Do this, use:

    style_cx = widget.get_style_context()

    new_path = Gtk.WidgetPath()
    new_path.append_type(Gtk.Window);
    new_path.append_type(Gtk.ProgressBar);

    style_cx.set_path(new_path)

    ...

(And of course instead of Gtk.ProgressBar, use any widget type you need
to draw)

--
Andrew


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