我用带有css样式的GTK3编写了程序,它在我的KDE上运行得很好。但问题是,在ubuntu和windows10上,样式只能部分发挥作用。我有这样的css文件:
window {
background-color: white;
}
button {
border: none;
color: white;
padding: 15px 32px;
text-decoration: none;
font-size: 16px;
background-color: #555555;
}
除了更改按钮的背景之外,其他一切都正常。这就是我加载css的方式:
GtkCssProvider *provider = gtk_css_provider_new ();
gtk_css_provider_load_from_path (provider, "styles.css", NULL);
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_USER);
我怎样才能让它工作?
我找到了解决方案:
window {
background-color: white;
}
button {
border: none;
padding: 0px;
text-decoration: none;
font-size: 16px;
}
button > label{
padding: 15px 32px;
background-color: #555555;
color: white;
}
您可以通过在~/.config/gtk-3.0/gtk.css
上编写css进行更改。
button.titlebutton.close:backdrop {
background-color: transparent;
}
button.titlebutton.close {
background-color: @theme_selected_bg_color;
}
参考文献:
- https://github.com/nana-4/materia-theme/issues/370#issuecomment-481256130
- https://asukiaaa.blogspot.com/2022/07/change-color-of-close-button-of-ubuntu2204.html