更改文本颜色GtkToggleToolButton在C code(GTK + 3) [英] Change text color for GtkToggleToolButton in C code (GTK+3)
问题描述
最近我发现改变GtkToggleToolButton文字的颜色使用CSS表(GTK 3.20)的方式:
Recently I found the way to change color of GtkToggleToolButton text with a CSS sheet (Gtk 3.20):
#histoToolGreen label {
color: green;
}
#histoToolBlue label {
color: blue;
}
要做到这一点,我改变了标签,而不是按钮的颜色。它运作良好。但现在我想在做C code中的相同。所以我写的:
To do that, I changed the color of the label rather than that of the button. It works well. But now I want doing the same in C code. So I write :
gtk_css_provider_load_from_data(provider, "#histoToolRed label {color: red;}", -1, NULL);
gtk_style_context_add_provider(
gtk_widget_get_style_context(lookup_widget("histoToolRed")),
GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
但是,这并不工作。我也试过,没有成功:
But that does not work. I also tried, with no success:
gtk_css_provider_load_from_data(provider, "* {color: red;}", -1, NULL);
和许多其他的事情。
有人能告诉我如何使用CSS提供商改变GtkToggleToolButton文本颜色C code吗?
Can someone tell me how to change color of GtkToggleToolButton text in C code using CSS provider ?
推荐答案
我一直没有取得进展试图在小部件级别添加CSS样式。我只设法得到它通过用的 gtk_css_provider_get_default 。
I've made no progress trying to add CSS styling at the widget level. I've only managed to get it to work by adding a style sheet at the application level with gtk_css_provider_get_default.
我所期待的,当我做了类似于你做了什么东西,该样式将被应用到我重视它的部件,以及它的所有儿童。我发现是这种风格只适用于个别的小工具,得到了供应商加入其中。
What I expected when I did something similar to what you've done is that the style would be applied to the widget I attached it to, and all of it's children. What I found is that style is only applied to the individual widget that got the provider added to it.
这篇关于更改文本颜色GtkToggleToolButton在C code(GTK + 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!