Reputation: 4072
Have a Gtk.Box()
and need add specific css only to widget. Have a dinamic class as Box called CustomBox
and have functions like setBackgroundColor(self, strRgbColor)
, need in each function modify the css only for that widget.
Example:
box1 = CustomBox()
box1.setPadding(10,10,0,0)
box2 = CustomBox()
box2.setBackgroundColor('#ff0000')
Need each widget with specific css.
Y have:
self.id = 'box_' + str(id(self))
box = Gtk.Box()
box.set_name(self.id)
# ...
css_provider = Gtk.CssProvider()
css_provider.load_from_data(('#' + self.id + '{ border: 1px solid red; }').encode())
context = Gtk.StyleContext()
# ... ??
Where self.id
is the unique id (with id(self)
), but how set the css_provider to box
?
Upvotes: 0
Views: 78
Reputation: 57854
Use context.add_provider()
to affect only the widget itself (not its children nor any other widgets) or Gtk.StyleContext.add_provider_for_screen()
to affect all created widgets in your program.
Upvotes: 1