Re: setting a button label overwrites label's color?



Tim Flechtner wrote:

hello gtkmmers,
i have an object of Gtk::Button, in which i set the object's label's color by calling code like:

void setButton(Gtk::Button& button, std::string& s, Gdk::Color color)
{
 b.get_child()->modify_fg(Gtk::STATE_NORMAL, color);
 b.set_label(s);
}

after this code executes, the button's label has reverted to the default color for label text. i believe that the call to set_label resets its color. if i invert the order of the two lines in the above function, i get the color i therein. i would *really* like to be able to updated the contents of the label without the color (and possibly other characteristics, such as font) resetting. does anyone know how i can do so?

thanks!
-tim
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list


Hey Tim:

Try this instead: (I'm assuming that you have not added any other children to the button outside of the text label by use of the button constuctor)

void setButton(Gtk::Button& button, Glib::ustring& str, Gdk::Color color)
{
   button.get_child()->modify_fg(Gtk::STATE_NORMAL, color);

// get the pango layout for the label child of the button and use the "set_text" method to change the text.
   button.get_child()->get_layout()->set_text(str);
}

I didn't have time to test this, but it should allow you to change the button text without altering anything else.
Sincerely,
Bob Caryl



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]