本文介绍了无法在GTK +中将CSS设置为指定的小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Vala和GTK +,现在我正在尝试将自定义CSS添加到指定的小部件。
我可以添加fe。 backgroudn GtkWidget但不是#sidebar

I'm using Vala with GTK+ and now I'm trying to add custom CSS to specified widget.I can add fe. backgroudn to GtkWidget but not for #sidebar

#sidebar { //It doesn't work
    color: white;
}

GtkWindow {  // It works
    background-color: red;
}

我将类添加到小部件中:

I'm adding class to widget like that:

sidebar = new Gtk.Label("Hello");
sidebar.set_name("sidebar");

它将颜色更改为GtkWindow,但不包含此标签。

And it's changes color to GtkWindow, but not for this label.

任何想法?

推荐答案

我没有在Vala中编程,但是您应该将类​​添加到StyleContext 。
这是在C

I haven't programmed in Vala, but you should add class to StyleContext.This is in C

   sidebar = gtk_label_new ("Hello');
   gtk_style_context_add_class ( gtk_widget_get_style_context ("mysidebar"), sidebar);

此外,stylesidebar已经在GtkStyle中定义。应该将CSS中的侧边栏改成其他的东西(侧边栏被视图,工具栏等使用)
但是如果你坚持,语法应该是:

Also, style "sidebar", is already defined in GtkStyle. You should change the "sidebar" in CSS into something else (sidebar is used by views, toolbar etc)But if you persist, the syntax should be:

   .mysidebar {
       #anything
   }

这篇关于无法在GTK +中将CSS设置为指定的小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 19:44