如何在gtk3中将特定的CSS类设置为小部件? (C) [英] how to set a specific css class to a widget in gtk3? (c)
本文介绍了如何在gtk3中将特定的CSS类设置为小部件? (C)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在gtk3中尝试使用CSS,但我不知道如何使用特定的类.
I'm trying css in gtk3 and I don't understand how to use specific class.
C代码:
provider = gtk_css_provider_new();
display = gdk_display_get_default();
screen = gdk_display_get_default_screen (display);
gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
gtk_css_provider_load_from_path(GTK_CSS_PROVIDER(provider),"styles.css",NULL);
enter_button = gtk_button_new_with_label("Print");
g_signal_connect(G_OBJECT(enter_button), "clicked", G_CALLBACK(print_entry_dialog),&t_data);
gtk_box_pack_start(GTK_BOX(hbox3), enter_button, TRUE, TRUE, 0);
Css(styles.css):
Css (styles.css):
GtkButton{
background: #669999;
text-shadow: 1px 1px 5px black;
box-shadow: 0px 0px 5px black;
border: 1px solid black;
}
以这种方式起作用:
但是我想设置一个'enter_button'类,该类只为'enter_button'设置属性,而不是为GtkButton名称下的所有小部件设置属性.
But I want to set a 'enter_button' class that set properties for only the 'enter_button', not for all widget under GtkButton name.
我阅读了有关gtk_style_context_add_class()函数的信息,但我不知道它如何与'styles.css'文件一起使用. 我该怎么办?
I read about gtk_style_context_add_class () func, but I don't know how it works with the 'styles.css' file. What I should do?
推荐答案
我以这种方式解决了:
GtkStyleContext *context;
enter_button = gtk_button_new_with_label("Print");
context = gtk_widget_get_style_context(enter_button);
gtk_style_context_add_class(context,"enter_button");
CSS:
.enter_button{
background: #669999;
text-shadow: 1px 1px 5px black;
border-radius: 3px;
box-shadow: 0px 0px 5px black;
}
有关更多信息,请参见: GtkStyleContext示例
For further informations look up here : GtkStyleContext examples
这篇关于如何在gtk3中将特定的CSS类设置为小部件? (C)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文