Can't set CSS to specified widget in GTK+

白昼怎懂夜的黑 提交于 2020-01-03 04:21:12

问题


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:


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
   }


来源:https://stackoverflow.com/questions/23722112/cant-set-css-to-specified-widget-in-gtk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!