I'm almost a gtk newbie, and I'm looking for a way to get the background color for the current theme in gtk. So this code:
GdkColor color = gtk_widget_get_style(mainWindowHandle)->bg[G开发者_StackOverflow社区TK_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!
精彩评论