brpaz
brpaz

Reputation: 3658

Gtk Application - CSS Styling GTK widgets is not working

I am building a simple GTK application but I am having issues styling it. Here is a screenshot

Its a very basic Gtk.Dialog with some Gtk.Box with Gtk.Label and Gtk.Entry inside. I want to give some margins to the dialog content and also align the labels to the left.

I read I need to do it with css, but I am having troubles getting in to work. I am loading my stylesheet like this:

style_provider = Gtk.CssProvider()
style_provider.load_from_data(GTK_STYLE)

Gtk.StyleContext.add_provider_for_screen(
           Gdk.Screen.get_default(),
            style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_USER
)

And here my expirements with the css file:

GTK_STYLE = """
* {
    background: blue;
    -GtkDialog-content-area-spacing: 10;
}

.label {
    background: red;
}

GtkLabel {
    color: red;
}

GtkDialog {
    background: red;
}
"""

From this css, only the global blue background is being applied. Nothing of my other style definitions are being applied.

What I am missing? Do I need to be more specific in the selectors? How do I know the hierarchy then?

Thank you for your help.

Upvotes: 2

Views: 1470

Answers (1)

Oliver
Oliver

Reputation: 385

The documentation lists styling properties under CSS nodes, see for instance the docs for GtkLabel: https://developer.gnome.org/gtk3/stable/GtkLabel.html

So I believe in order to set the color of all GtkLabels you'd have to write (untested):

label {
    color: red;
}

For more information go to https://developer.gnome.org/gtk3/stable/chap-css-overview.html

Upvotes: 1

Related Questions