问题
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!
回答1:
As far as I know you won't able to use the code above because Qt uses Gtk2 and not Gtk3. This means that you will get a core dump with a message similar to:
Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in
the same process is not supported
You might be able to do something hacky by accessing the Gtk 3 libs from a diff process, but is a hack.
来源:https://stackoverflow.com/questions/7903518/gtk3-getting-a-styles-class-property