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 551912 - Unable to set text color of ToggleButton using modify_text method
Unable to set text color of ToggleButton using modify_text method
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
2.12.x
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on: 566945
Blocks:
 
 
Reported: 2008-09-12 05:59 UTC by Matt Hayes
Modified: 2014-02-01 09:51 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Matt Hayes 2008-09-12 05:59:29 UTC
I am unable to modify the text color of a ToggleButton using the supplied modify_text method.  The only method that seems to do anything at all is modify_bg.  I have found a few people on the internet facing the same problem.
Comment 1 Murray Cumming 2008-10-20 11:23:48 UTC
Do you have this problem only with ToggleButton, or also with Button and other widgets?
Comment 2 Murray Cumming 2008-11-14 09:19:33 UTC
Please respond.
Comment 3 Matt Hayes 2008-11-14 19:39:40 UTC
I'm sorry for the late response.  Yes, it appears to be both ToggleButton and Button, as well as Label.  These are the only widgets I've tried it on, but it appears the method does absolutely nothing.
Comment 4 Matt Hayes 2008-11-14 19:45:54 UTC
Oh, by the way,  modify_fg *WILL* change the text color on a Label, but not on a Button or ToggleButton.  So, not sure if this helps at all.  You would think modify_text should change the text color of a Label, but I am not sure if that is the behavior in the C gtk+ libraries as well.
Comment 5 Murray Cumming 2008-11-14 20:46:01 UTC
I guess that you should change the text color of the label that is inside the button. If so, I guess that this should be clearer in the documentation. And it should be clearer that it's not recursive.
Comment 6 Matt Hayes 2008-11-14 21:05:42 UTC
Okay, so that works -- grabbing the child widget of the button and using modify_fg on it.

It leaves the question, what does modify_text even do then?  It doesn't seem to change the text color on any widget, even a label, which seems most apparent that it would.  It appears that in other gtk libraries like python-gtk modify_text will modify the label text color contained in any widget.  So this was probably not implemented correctly.
Comment 7 Murray Cumming 2009-01-07 21:28:05 UTC
I filed a GTK+ bug about hte documenation so we can make it clearer in gtkmm too if they agree: Bug #566945
Comment 8 Kjell Ahlstedt 2010-11-03 15:48:20 UTC
Here's a comment that will perhaps add to the confusion.

In the documentation of GTK+ there is a section called 'Resource files'.
It says that for each widget, you can specify 4*5 colors: bg[state], fg[state],
base[state], text[state], where state is one of normal, active, prelight,
selected, insensitive. It also says that bg and fg are used for the background
and foreground of most widgets, base and text are used for the background and
foreground of widgets displaying editable text, e.g. GtkText, GtkEntry,
GtkList, and GtkCList.

This seems to indicate that GtkLabel uses fg and not text, since it's not
editable. And GtkLabel does not draw its own background, so it uses neither
bg nor base.

And what about the label in a button? I made some tests on Ubuntu 10.10 with
gtkmm version 2.20.3 and gtk+ 2.22.0. Here are the results.

The text in a Gtk::Button, ToggleButton, or CheckButton is drawn by a Label
widget, which is the child of the button. It uses its own fg color, not the
color of the button. Depending on the state of the button, the label uses the
color belonging to one of the states normal, active, prelight (when the mouse
cursor is over the button), or insensitive.

The background in a Button or ToggleButton is drawn by the button itself,
using the bg color belonging to the current state of the button.

The color selection for the check box in a CheckButton is strange. The base
color of the button is used for the background, and the text color for
the check mark. The colors of state normal are used whether the button is
checked or not.

Gtk::Entry uses the base and text colors, just as the gtk+ documentation says.

Thus the base and text colors are used by some widgets. But Matt Hayes's
question in comment 6 is still legitimate after a slight rewording:
What are modify_base and modify_text good for? Couldn't all widgets use
modify_bg and modify_fg?
Comment 9 Kjell Ahlstedt 2011-05-05 11:48:17 UTC
In gtkmm3 modify_text and modify_fg have been replaced by override_color.
modify_base and modify_bg have been replaced by override_background_color.
A simplification. But there are more widget states: normal, active, prelight,
selected, insensitive, inconsistent, and focused.

The text in a button is still a label, which is the child widget of the button.
To change the text color, you must call override_color() on the child widget.
As far as I can see, that's no better documented in gtk+3 than in gtk+2.
Comment 10 Murray Cumming 2013-09-25 09:55:56 UTC
Maybe someone can suggest a documentation patch for GTK+.
Comment 11 Kjell Ahlstedt 2013-10-07 17:05:45 UTC
I have attached a patch to the gtk+ bug 566945.

I have also pushed a patch to gtkmm.
https://git.gnome.org/browse/gtkmm/commit/?id=e1e2e8a8b7e820180754395f43f5cb5249f3be73
It uses _WRAP_METHOD on gtk_widget_override_color() and
gtk_widget_override_background_color(), which is possible now that _WRAP_METHOD
can reorder parameters. If the documentation of gtk_widget_override_color() is
improved, the improvement will then be copied to Gtk::Widget::override_color()
when gtk_docs.xml is regenerated.
Comment 12 Kjell Ahlstedt 2014-02-01 09:51:08 UTC
The documentation of gtk_widget_override_color() and
Gtk::Widget::override_color() has been improved. Added text:

  This function does not act recursively. Setting the color of a container
  does not affect its children. Note that some widgets that you may not think
  of as containers, for instance Gtk::Buttons, are actually containers.

It's unlikely that override_[background_]color() will ever be made to act
recursively when applied to a container. Even though it would be nice for
buttons and a few other widgets, I'm not sure it would be considered an
improvement for containers in general.