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?

1 Answer 1

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
   }
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.