GNOME Bugzilla – Bug 551912
Unable to set text color of ToggleButton using modify_text method
Last modified: 2014-02-01 09:51:08 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.
Do you have this problem only with ToggleButton, or also with Button and other widgets?
Please respond.
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.
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.
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.
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.
I filed a GTK+ bug about hte documenation so we can make it clearer in gtkmm too if they agree: Bug #566945
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?
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.
Maybe someone can suggest a documentation patch for GTK+.
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.
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.