1

I'm using Vala with GTK+ and now I'm trying to add custom CSS to specified widget. I can add fe. backgroudn to GtkWidget but not for #sidebar

#sidebar { //It doesn't work                                                           
    color: white;                                                                
}                                                                       

GtkWindow {  // It works                                                                    
    background-color: red;                                                                        
}   

I'm adding class to widget like that:

sidebar = new Gtk.Label("Hello");
sidebar.set_name("sidebar");

And it's changes color to GtkWindow, but not for this label.

Any ideas?

Sekhmet
  • 523
  • 1
  • 7
  • 21

1 Answers1

5

I haven't programmed in Vala, but you should add class to StyleContext. This is in C

   sidebar = gtk_label_new ("Hello');
   gtk_style_context_add_class ( gtk_widget_get_style_context ("mysidebar"), sidebar);

Also, style "sidebar", is already defined in GtkStyle. You should change the "sidebar" in CSS into something else (sidebar is used by views, toolbar etc) But if you persist, the syntax should be:

   .mysidebar {
       #anything
   }
Sekhmet
  • 523
  • 1
  • 7
  • 21
luciomrx
  • 1,165
  • 1
  • 7
  • 7
  • 1
    `sidebar.get_style_context().add_class("desidebar");` Worked pretty well. I've tried this before, but I've used "sidebar" class name and it didn't worked. Now it works :) Thanks. – Sekhmet May 19 '14 at 16:54