gtk3 css 与 GtkNotebook

发布于 2024-12-05 06:44:37 字数 2724 浏览 1 评论 0原文

我正在使用GTK3.0.12,并尝试创建一个使用CSS具有不同标签背景颜色的笔记本。除了背景之外,我可以为所有内容设置不同的属性。我该怎么做?

/*  Compile with:
*  gcc -Wall -o notebook1 `pkg-config --cflags --libs gtk+-3.0` notebook1.c
*/
#include <gtk/gtk.h>

int main(int argc, char *argv[] )
{
  GtkWidget *window;
  GtkWidget *mynotebook;
  GtkWidget *grid;

gtk_init (&argc, &argv);

GtkCssProvider *provider = gtk_css_provider_new ();
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     
         (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider),
                                 " GtkNotebook {\n"    // or  " .notebook {\n"
                                 "   -GtkWidget-focus-line-width: 0;\n"
                                 "}\n"
                                 " .notebook tab {\n"  // or  " * tab {\n"
                                 "   padding: 10 20 10 20;\n"
                                 "   border-radius: 8;\n"
                                 "   background-color: blue;\n"
                                 "}\n"
                                 " GtkNotebook tab GtkLabel#settings_tab {\n"
                                 "   color: white;\n"
                                 "   font: Serif 12;\n"
                                 "}\n"
                                 " .notebook tab GtkLabel#report_tab {\n"
                                 "   color: red;\n"
                                 "   font: Sans 12;\n"
                                 "}\n", -1, NULL);

g_object_unref (provider);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 800, 480);
g_signal_connect (GTK_WIDGET (window), "destroy",
                  G_CALLBACK (gtk_main_quit), NULL);
mynotebook = gtk_notebook_new ();
gtk_widget_set_name (GTK_WIDGET(mynotebook), "notebook");
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (mynotebook), GTK_POS_TOP);

grid = gtk_grid_new();
GtkWidget *report_label = gtk_label_new ("Report");
gtk_widget_set_name (GTK_WIDGET(report_label), "report_tab");

gtk_container_add(GTK_CONTAINER(window),mynotebook);
gtk_container_add(GTK_CONTAINER(mynotebook),grid);
gtk_notebook_set_tab_label(GTK_NOTEBOOK(mynotebook), grid, report_label);

GtkWidget *grid2 = gtk_grid_new ();
GtkWidget *settings_label = gtk_label_new ("Settings");
gtk_widget_set_name (GTK_WIDGET(settings_label), "settings_tab");

gtk_notebook_insert_page (GTK_NOTEBOOK(mynotebook),  GTK_WIDGET(grid2),
             GTK_WIDGET(settings_label), -1);

gtk_widget_show_all(window);
gtk_main();
return(0);
}

I'm using gtk3.0.12 and trying to create a notebook that has different tab background colors using css. I can set different properties for every thing but the background. How do I do this?

/*  Compile with:
*  gcc -Wall -o notebook1 `pkg-config --cflags --libs gtk+-3.0` notebook1.c
*/
#include <gtk/gtk.h>

int main(int argc, char *argv[] )
{
  GtkWidget *window;
  GtkWidget *mynotebook;
  GtkWidget *grid;

gtk_init (&argc, &argv);

GtkCssProvider *provider = gtk_css_provider_new ();
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     
         (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider),
                                 " GtkNotebook {\n"    // or  " .notebook {\n"
                                 "   -GtkWidget-focus-line-width: 0;\n"
                                 "}\n"
                                 " .notebook tab {\n"  // or  " * tab {\n"
                                 "   padding: 10 20 10 20;\n"
                                 "   border-radius: 8;\n"
                                 "   background-color: blue;\n"
                                 "}\n"
                                 " GtkNotebook tab GtkLabel#settings_tab {\n"
                                 "   color: white;\n"
                                 "   font: Serif 12;\n"
                                 "}\n"
                                 " .notebook tab GtkLabel#report_tab {\n"
                                 "   color: red;\n"
                                 "   font: Sans 12;\n"
                                 "}\n", -1, NULL);

g_object_unref (provider);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 800, 480);
g_signal_connect (GTK_WIDGET (window), "destroy",
                  G_CALLBACK (gtk_main_quit), NULL);
mynotebook = gtk_notebook_new ();
gtk_widget_set_name (GTK_WIDGET(mynotebook), "notebook");
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (mynotebook), GTK_POS_TOP);

grid = gtk_grid_new();
GtkWidget *report_label = gtk_label_new ("Report");
gtk_widget_set_name (GTK_WIDGET(report_label), "report_tab");

gtk_container_add(GTK_CONTAINER(window),mynotebook);
gtk_container_add(GTK_CONTAINER(mynotebook),grid);
gtk_notebook_set_tab_label(GTK_NOTEBOOK(mynotebook), grid, report_label);

GtkWidget *grid2 = gtk_grid_new ();
GtkWidget *settings_label = gtk_label_new ("Settings");
gtk_widget_set_name (GTK_WIDGET(settings_label), "settings_tab");

gtk_notebook_insert_page (GTK_NOTEBOOK(mynotebook),  GTK_WIDGET(grid2),
             GTK_WIDGET(settings_label), -1);

gtk_widget_show_all(window);
gtk_main();
return(0);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮烟 2024-12-12 06:44:37

我在标签上遇到了一些困难,
您是否尝试过类似的东西:

background-color: shade (#000000, 0.90);

background-image: -gtk-gradient (linear, left top, left bottom,
                                     from (shade (#000000, 1.30)),
                                     to (shade (#ffffff, 1.05)));

我为GTK3找到的信息在这里
http://deverice.gnome.gnome.gnme.orgg/gtk3/3.3/gtkcssssprovider.htmel.gtk3/

Im having some difficulties with tabs to,
did you try something like:

background-color: shade (#000000, 0.90);

or

background-image: -gtk-gradient (linear, left top, left bottom,
                                     from (shade (#000000, 1.30)),
                                     to (shade (#ffffff, 1.05)));

only info I found for gtk3 is here
http://developer.gnome.org/gtk3/3.3/GtkCssProvider.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文