I do not have a code error, I have just looked everywhere and cannot figure out how to do this. I want to get the color of a Gtk::widget, the Gtk::label. I can override the color of a label like this: l.override_color( c, l.get_state_flags() ); , but I have no idea how to get that color back from the label, thanks!
Asked
Active
Viewed 2,153 times
1 Answers
3
This is a way to set and get the color of a label:
// Set Color
Gtk::Label label("some label");
label.override_color (Gdk::RGBA("red"), Gtk::STATE_FLAG_NORMAL);
// Get Color
Glib::RefPtr<Gtk::StyleContext> stylecontext = label.get_style_context();
Gdk::RGBA color = stylecontext->get_color(Gtk::STATE_FLAG_NORMAL);
std::cout << color.to_string(); // Display color as "rgb(x, x, x)"

GTK 1.2.6 fanboy
- 839
- 1
- 5
- 20