Marco Rossi Marco Rossi - 4 months ago 22
CSS Question

how to set a specific css class to a widget in gtk3? (c)

I'm trying css in gtk3 and I don't understand how to use specific class.

C code:

provider = gtk_css_provider_new();
display = gdk_display_get_default();
screen = gdk_display_get_default_screen (display);
gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);

enter_button = gtk_button_new_with_label("Print");
g_signal_connect(G_OBJECT(enter_button), "clicked", G_CALLBACK(print_entry_dialog),&t_data);
gtk_box_pack_start(GTK_BOX(hbox3), enter_button, TRUE, TRUE, 0);

Css (styles.css):

background: #669999;
text-shadow: 1px 1px 5px black;
box-shadow: 0px 0px 5px black;
border: 1px solid black;

In this way it works : enter image description here

But I want to set a 'enter_button' class that set properties for only the 'enter_button', not for all widget under GtkButton name.

I read about gtk_style_context_add_class () func, but I don't know how it works with the 'styles.css' file.
What I should do?


I solved in this way:

GtkStyleContext *context;
enter_button = gtk_button_new_with_label("Print");
context = gtk_widget_get_style_context(enter_button);


    background: #669999;
    text-shadow: 1px 1px 5px black;
    border-radius: 3px;
    box-shadow: 0px 0px 5px black;

For further informations look up here : GtkStyleContext examples