Let's imagine I have next code
css = b"""
.my_css
{
background-color: red;
}"""
self.style_provider = Gtk.CssProvider()
self.style_provider.load_from_data(css)
Gtk.StyleContext.add_provider_for_display(Gdk.Display().get_default(),self.style_provider,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
self.box1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.box2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.box3 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.box4.get_style_context().add_class("my_css")
The problem is - when I'm adding provider for display for custom css - another elements starting to use default theme Adwaita, and ignoring current theme if it's not Adwaita or Adwaita-dark.
My live examples:
With system theme Adwaita - fine and using theme With system theme Adwaita dark - is fine too But with any another theme - it ignored
If I'm using self.style_provider.load_from_path("/usr/share/themes/"+CURRENT_THEME+"/gtk-3.0/gtk.css") I have working theme for all elements, but my custom css are overriding by loaded theme.
With self.style_provider.load_from_path - theme applied to window, but my custom CSS ignored
I tried everything what I know - but no success.
Function Gtk.StyleContext.add_provider_for_display() - applying CSS for entire window I need apply only certain CSS to only certain elements, without touching another.
May be there is some method just to add style, like
self.box4.add_style("{background-color: red;border: 1px solid green;}")
just don't use
Gtk.StyleContext.add_provider_for_display. You can add the provider individually for each widget like this: