How to style a GtkLabel with CSS?

前端 未结 1 1319
时光说笑
时光说笑 2020-12-31 23:54

I\'m trying to use CSS to style a GtkLabel. I would like to change the color and font size of the label. Here is my C code:

#include 

int m         


        
相关标签:
1条回答
  • 2021-01-01 00:36

    Currently, CSS providers are not inherited to the children style contexts. So you need to add the CSS provider to the screen using gtk_style_context_add_provider_for_screen()

    Try changing

    gtk_style_context_add_provider(gtk_widget_get_style_context(window),
                                   GTK_STYLE_PROVIDER(cssProvider),
                                   GTK_STYLE_PROVIDER_PRIORITY_USER);
    

    to

    gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
                                              GTK_STYLE_PROVIDER(cssProvider),
                                              GTK_STYLE_PROVIDER_PRIORITY_USER);
    

    I don't think gtk supports multiple screens these days, but gtk_widget_get_screen() could be used to replace gdk_screen_get_default().

    0 讨论(0)
提交回复
热议问题