我创建了一个使用Gtk的文本编辑器,并希望用Css设置它。我该怎么做顺便说一句,我正在使用Code Blocks IDE。这是第一次使用gtk和css,所以我不知道在哪里放置文件等。我添加了gtkcssprovider代码但它似乎没有工作。有人可以帮我解决这个问题吗?谢谢
这是我的文件结构:
testCode
---bin/
---obj/
---file.c
---file.h
---main.c
---testCode (project file)
---testCode.depend
---testCode.layout
---theme.css
继承我的main.c:
int main( int argc, char *argv[])
{
GtkWidget *scroll;
//GdkColor color;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 800, 500);
gtk_window_set_title(GTK_WINDOW(window), "Notepad");
vBox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vBox);
GtkCssProvider* css_provider = gtk_css_provider_new();
if(!gtk_css_provider_load_from_path(css_provider, "theme.css", NULL))
{
g_object_unref(css_provider);
return;
}
GdkDisplay* display = gdk_display_get_default();
GdkScreen* screen = gdk_display_get_default_screen(display);
gtk_style_context_add_provider_for_screen(screen,
GTK_STYLE_PROVIDER(css_provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
accelGroup = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(window), accelGroup);
createMenuBar();
createToolBar();
scroll = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
textView = gtk_text_view_new ();
gtk_container_add(GTK_CONTAINER(scroll), textView);
gtk_box_pack_start(GTK_BOX(vBox),
scroll,
TRUE,
TRUE,
0);
gtk_box_pack_start (GTK_BOX (vBox), textView, 1, 1, 0);
callBackFunction();
gtk_widget_show_all(window);
gtk_main();
return 0;
}
继承theme.css:
GtkWindow {
background-image: -gtk-gradient (linear,
center top, center bottom,
color-stop(0.5,green),
color-stop(0.5,blue),
}