E
E
Eugene2020-07-12 14:23:04
GTK+
Eugene, 2020-07-12 14:23:04

Why does only one css style property work in a gtk application?

I decided to try my hand at building a window application using GTK3. I create a window and attach styles to it like this:

GtkCssProvider *cssProvider = gtk_css_provider_new();
    if(gtk_css_provider_load_from_path(cssProvider, "cpp/test/style.css", NULL)){
        gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
    }
    
    else
        g_printerr ("Ошибка открытия файла стилей");

    builder = gtk_builder_new ();
    if (gtk_builder_add_from_file (builder, "cpp/test/window.ui", &error) == 0){
        g_printerr ("Error loading file: %s\n", error->message);
        g_clear_error (&error);
        return 1;
    }

And I attached a style file to it for verification:
window{
    background-color: Peru;
}


GtkButton {
    background-color: red;
}

#OneLvl{
    background-color: red;
    color: white;
    font-weight: bold;
    font-size: 50px;
}


But from this style file, only the properties for window work , no other style block works. What could be the problem? The elements themselves with the required IDs are in the window.ui file, but I can’t understand why the properties are not applied to them.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tony, 2021-03-18
@jenya92

1. The global theme of your Desktop environment can take precedence and only display what it doesn't ruin the "look and feel of the application". That is it is banal to disconnect X properties. Checked by changing the topic.
2. The last property is applied, as in the web world, overwriting the previous (similar) one.
3. CSS under Gtk is different from CSS Web, you need to study the API deeper.
4. Maybe you should have used a dot before the name, not a pound sign.
5. See examples on github or https://gitlab.com/gavr123456789/vala-css-examples...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question