GNOME Bugzilla – Bug 656461
gtk_widget_override_background_color not always honored.
Last modified: 2015-03-12 13:20:16 UTC
When the theme wants an image (as a gradient) as background, a call to gtk_widget_override_background_color has no effect. If this is a feature, then, please, provide a gtk_widget_override_background function.
I ran into this issue today. It would be great to fix this in some way, because currently gtk_widget_override_background_color() doesn't work as expected if the theme uses an image/gradient -- which is the case of GNOME's default theme (Adwaita) for entries for example --, and there is no other way to make it work than using the CSS API; but this function is supposed to prevent having to use the more complex CSS API for such simple cases. Also, if the solution of adding additional API to set the background-image or the whole background, it'd be good to update the documentation to warn the user that set_background_color() might not be enough.
Confirming, using gtk_widget_override_background_color() on a GtkEntry changes its selection background (color for selected text), but the background of the widget, in Adwaita, is still white, unless the widget is disabled (insensitive), when the background is used for drawing too.
Confirmed, gtk_widget_override_background_color() isn't working as expected. Widget color only changed on insensitive mode.
Right, I did workaround this by unsetting background image of the GtkEntry, with a tweak in its CSS. See the second chunk of [1]. There might be better ways, like I was pointed to gtk_style_context_add_class(), but as the [1] works in Evolution, I didn't pay much attention. [1] https://git.gnome.org/browse/evolution/commit/?id=3775df1
Created attachment 253922 [details] Minimal test case I ran into this today as well and its a bit frustrating that it does not work with the default theme. I used the workaround from Milan (thanks!) and provide a custom css provider, but that looks excessive for just changing the background color of a button. Attached is a small test app and a patch that is not complete, but maybe provides a starting point for a fix? It seems like the workaround in the css is to clean the background, so maybe the override_color code should do exactly this? Alternatively I think a hint in the docstring of the function would be useful, something like "Note that this does not work with the default theme or any theme that uses gradients"
Created attachment 253923 [details] [review] Patch that simply unsets the background image on gtk_widget_override_background_color This is probably not correct, but maybe it helps moving towards a solution for this bug.
Please accept this patch, it saves many projects from implementing ugly workarounds. (I'm a Wireshark developer and would like to upgrade to GTK+ 3.14 instead of putting hacks in our code.)
gtk_widget_override_background_color has been deprecated, since it doesn't match the CSS background model.
It is understandable, but please take a look at #738841, because the CSS model is broken as well in 3.14.
if gtk_widget_override_background has been deprecated the documentation should be updated to reflect this. i wasted time trying to get it to work.
(In reply to jon.orebro from comment #10) > if gtk_widget_override_background has been deprecated the documentation > should be updated to reflect this. i wasted time trying to get it to work. The symbol has been deprecated in the development version of GTK: https://developer.gnome.org/gtk3/unstable/GtkWidget.html#gtk-widget-override-background-color