简体   繁体   English

提取gtk主题背景颜色

[英]Fetching gtk theme background color

I'm almost a gtk newbie, and I'm looking for a way to get the background color for the current theme in gtk. 我几乎是gtk的新手,并且正在寻找一种方法来获取gtk中当前主题的背景色。 So this code: 所以这段代码:

GdkColor color = gtk_widget_get_style(mainWindowHandle)->bg[GTK_STATE_NORMAL];

works only after the main window is shown, before returns an strange ugly gray. 仅在显示主窗口之后才能工作,然后返回奇怪的难看的灰色。

Try to attach to the widget's "realize" signal and then grab the style information you want. 尝试附加到小部件的“实现”信号,然后获取所需的样式信息。

static void
widget_realized_cb (GtkWidget *widget) {
  GdkColor *color = NULL;
  GtkStyle *style = gtk_widget_get_style (widget);

  if (style != NULL) {
    color = style->bg[GTK_STATE_NORMAL];

    /* Do whatever you want with it here */
  }
}

void foobar () {
  g_signal_connect (mainWindowHandle,
                    "realize",
                    G_CALLBACK (widget_realized_cb),
                    NULL);
}

I've added a 我添加了一个

gtk_widget_realize(mainWindowHandle);

before the gtk_widget_get_style and works perfectly! 在gtk_widget_get_style之前,并且效果很好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM