Getting gradients from StyleContext

I’m having trouble finding a way of extracting the background-image component of a widget’s css style context. The data appears to be locked away behind StyleContext and only a pre-made paint background function is able to use it.

This is making it hard to construct a custom ruler widget for inkscape with a background that’s defined outside of the code much more difficult. But perhaps I’ve missed something in the docs? Any advice would be welcome.

I’m assuming GTK3, as you’re talking about Inkscape.

If you want to draw a widget background with CSS, you must use gtk_render_background(). You cannot query the CSS style machinery for the colors and then draw them manually yourself with Cairo.

1 Like

Yes, this is as I have found.

Although there’s a very interesting bug if you try and paint over other things with a gradient that goes from solid to transparent. A small square of the original color is painted on top, the size of the original allocation. It’s possibly a caching bug inside cairo or gtk.

For now we’re going to take the solid background color and construct the gradient internally. Which is a shame.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.