Unable to set css_name when implementing a class. ( Vala with Gtk4 )

I have implemented a class that extend Gtk.Widget, but i was unable to set the property css_name, this code won’t work. Where I doing wrong?

namespace FileBrowser {
    [GtkTemplate (ui = "/org/example/vala/filebrowser/ui/welcome-widget.ui")]
    public class WelcomeWidget : Gtk.Widget {

        /*      -------        */

        public WelcomeWidget () {
            Object( css_name: "welcome" );
            // this.set_css_name ("welcome");
        }

    }
}

I found the solution by myself, that is to add a static constructor to the class

static construct {
    set_css_name ("welcome");
 }

PS: Object( css_name: "welcome" ); is not neded.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.