After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 656461 - gtk_widget_override_background_color not always honored.
gtk_widget_override_background_color not always honored.
Status: RESOLVED WONTFIX
Product: gtk+
Classification: Platform
Component: Widget: Other
3.0.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks: 655858
 
 
Reported: 2011-08-13 14:49 UTC by Jean Bréfort
Modified: 2015-03-12 13:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Minimal test case (372 bytes, text/x-python)
2013-09-03 07:29 UTC, Michael Vogt
  Details
Patch that simply unsets the background image on gtk_widget_override_background_color (1.42 KB, patch)
2013-09-03 07:31 UTC, Michael Vogt
none Details | Review

Description Jean Bréfort 2011-08-13 14:49:18 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.
Comment 1 Colomban Wendling 2012-09-28 22:10:01 UTC
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.
Comment 2 Milan Crha 2012-11-21 09:32:43 UTC
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.
Comment 3 Ardhan Madras 2013-03-17 08:27:43 UTC
Confirmed, gtk_widget_override_background_color() isn't working as expected. Widget color only changed on insensitive mode.
Comment 4 Milan Crha 2013-03-18 10:19:07 UTC
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
Comment 5 Michael Vogt 2013-09-03 07:29:20 UTC
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"
Comment 6 Michael Vogt 2013-09-03 07:31:23 UTC
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.
Comment 7 Balint Reczey 2014-06-24 09:47:36 UTC
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.)
Comment 8 Matthias Clasen 2014-10-20 03:51:54 UTC
gtk_widget_override_background_color has been deprecated, since it doesn't match the CSS background model.
Comment 9 Balint Reczey 2014-10-20 07:16:03 UTC
It is understandable, but please take a look at #738841, because the CSS model is broken as well in 3.14.
Comment 10 jon.orebro 2015-03-12 13:06:53 UTC
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.
Comment 11 Emmanuele Bassi (:ebassi) 2015-03-12 13:20:16 UTC
(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