Styling with CSS in Custom Widgets

Hi.

I’m currently writing custom widgets in pure python by overriding the do_snapshot function.
Thats works pretty well.
But now I would like to be able to style my custom widget using CSS but I have no idea how I would access the information. (like color, background-image, marings/padding, …)

I try loading the CSS with a CssProvider and use the

get_style_property

method as describte in the documenation but unfortunately that function is not exposed in python.

So any help would be apprivated.

Martin

You don’t.

Only widgets can be styled with CSS, and that happens automatically inside GTK.

Custom rendering is, by definition, custom and cannot be styled with CSS.

You should replace your custom rendering with real widgets: it was a lot more expensive in older versions of GTK, but that’s not true any more in GTK4.

1 Like

OK. Thanks for the fast response.
I will that try to compose my custom widgets with standard GTK4 widgets.

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