1

I'm trying to get the text color of a class of a GTK style. I have a GtkStyleContext with the widget path and the classes that I want to get their properties.

GtkWidgetPath* widgetPath = gtk_widget_path_new ();
gtk_widget_path_append_type(widgetPath, GTK_TYPE_WINDOW);
gtk_widget_path_iter_set_name(widgetPath, -1 , "UnityPanelWidget");

GtkStyleContext *context = gtk_style_context_new();
gtk_style_context_set_path(context, widgetPath);
gtk_style_context_add_class(context, "gnome-panel-menu-bar");
gtk_style_context_add_class(context, "unity-panel");

I used gtk_style_context_lookup_color and it gets the normal text color but not the text color in gnome-panel-menu-bar or unity-panel.

I tried using GtkCssProvider but it gets the generic style without the classes I added.

I'm using it in a Qt application to get a native GTK3 look and feel. This code is working fine in a GTK application.

Thanks!

4

1 回答 1

0

据我所知,您将无法使用上面的代码,因为 Qt 使用 Gtk2 而不是 Gtk3。这意味着您将获得一个核心转储,其中包含类似于以下内容的消息:

Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in 
the same process is not supported

您可以通过从 diff 进程访问 Gtk 3 库来做一些 hacky,但这是一个 hack。

于 2012-02-20T13:34:27.040 回答