一个小代码,以解释我的问题 与gtk 3.10.8代码belox运行正常与蓝色窗口
/* Compile with:
* gcc -Wall windox_css.c -o windox_css `pkg-config --cflags --libs gtk+-3.0`
*/
#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
GtkWidget *window;
/*--- CSS -----------------*/
GtkCssProvider *provider;
GdkDisplay *display;
GdkScreen *screen;
/*-------------------------*/
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW(window),
500, 300);
g_signal_connect (GTK_WIDGET(window),
"destroy",
G_CALLBACK (gtk_main_quit),
NULL);
/*------ CSS ---------------------------------------------------------------------------------------------------------------*/
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_APPLICATION);
//"-GtkWidget-focus-line-width: 0;\n"
gtk_css_provider_load_from_data (GTK_CSS_PROVIDER(provider),
" GtkWindow {\n"
" -GtkWindow-resize-grip-height: 0;\n" /* not guaranteed, can be overridden by window manger */
" -GtkWindow-resize-grip-width: 0;\n" /* not guaranteed, can be overridden by window manger */
" background-color: blue;\n" /* named color units */
" background-color: rgb (0, 0, 255);\n" /* rgb color units, overrides the previous "background-color" assignment */
" background-color: rgba (0,0,255,1);\n" /* rgba color units, overrides the previous "background-color" assignment */
" background-color: #0000FF;\n" /* hexadecimal color units, overrides the previous "background-color" assignment */
" background-color: shade(blue, 1.0);\n" /* overrides previous color assignment */
"}\n", -1, NULL);
g_object_unref (provider);
/*----------------------------------------------------------------------------------------------------------------------------*/
gtk_widget_show_all (window);
gtk_main ();
return (0);
}
新版本gtk 3.22.25窗口保持白色。 什么意思?你能帮我理解我必须改变的东西吗?
答案 0 :(得分:0)
在gtk +参考中很容易找到答案。自3.20 css改变。
所有小部件名称为GtkLabel都有一个css名称,如标签减去没有Gtk !!!! 例如
gboolean css_flag_320 = check_gtk();
if (css_flag_320)
{
gtk_css_provider_load_from_data (GTK_CSS_PROVIDER(provider),
" window {\n"
" -widget-focus-line-width: 0;\n"
" -window-resize-grip-height: 0;\n" /* not guaranteed, can be overridden by window manger */
" -window-resize-grip-width: 0;\n" /* not guaranteed, can be overridden by window manger */
" background-color: shade(darkgreen, 1.0);\n"
"}\n"
"/* gestion du bouton */\n"
"button {\n"
"background-image: -gtk-gradient (radial,\n"
"0.1 0.1, 0.2,\n"
"0.2 0.2, 1,\n"
" from (lightgreen),\n"
" to (shade (red, 0.9)));\n"
" }\n"
"/* gestion du bouton */\n"
"textview:active {\n"
"background-image: -gtk-gradient (radial,\n"
"0.1 0.1, 0.2,\n"
"0.2 0.2, 1,\n"
"from (red),\n"
"to (shade (yellow, 0.4)));\n"
"}\n"
"/* gestion du dialogue */\n"
"dialog{color: black;font-size: 110%; font-family: Helvetica, sans-serif; }\n"
"dialog{background-color: pink; }\n"//color = #F00 ou pink
"/* gestion du dialogue d'erreur */\n"
"messagedialog{color: black;font-size: 110%; font-family: Helvetica, sans-serif; }\n"
"messagedialog{background-color: orange; }\n"
"/* mise en cohérence de couleur du scroll et du notebook conseillée */\n"
" .scrollwindow {color: red;}\n"
"/* gestion du notebook */\n"
"notebook arrow:nth-child(first) { color: red ;}\n" // ne sert que pour le triangle du scrolling qui apparait en red
"notebook arrow:nth-child(last) { color: orange ;}\n" // ne sert que pour le triangle du scrolling qui apparait en red
"notebook #normal {\n" // normalement .notebook devrait être ok ???
" padding: 10px 20px 10px 20px;\n"
" border-radius: 8px;\n"
" background-color: shade(lightblue, 1.0);}\n"
"notebook #modified {\n" // normalement .notebook devrait être ok ??? et .modified ne fonctionne pas
" padding: 10px 20px 10px 20px;\n"
" border-radius: 8px;\n"
" background-color: yellow;\n"
"}\n"
".tooltip{background-color: yellow;}",
-1, NULL); //color = #f90192