Gtk::Style::set_bg()



Hi, I'm trying to use Gtk::Style to set the background color of a Gtk::Label. It is for the display of a 
calculator I'm making. I'm using two Gtk::Labels for the display (2 levels) because I need things to be right 
justified, but I also want the display to be a little nicer to read than just a Gtk::Label - I would like a 
white background. Better would even be to read the user's current theme to get the right background color, 
but I'll take baby steps. Thanks to the help of some nice people on this mailing list, I've got the right 
justification working, but now need to set the background color properly.

My code looks something like:
...
Gtk::Label *histDisplayLabel = manage(new class Gtk::Label(_("")));
Gtk::Label *currDisplayLabel = manage(new class Gtk::Label(_("0.")));
Gtk::VBox *displayVBox = manage(new class Gtk::VBox(true, 0));
Gtk::Frame *displayFrame = manage(new class Gtk::Frame());
...
histDisplayLabel->set_name("histDisplayLabel");
histDisplayLabel->set_alignment(1, 0.5);
histDisplayLabel->set_padding(2, 0);
currDisplayLabel->set_name("currDisplayLabel");
currDisplayLabel->set_alignment(1, 0.5);
currDisplayLabel->set_padding(2, 0);
displayVBox->set_name("displayVBox");
displayVBox->set_border_width(2);
displayVBox->pack_start(*histDisplayLabel, false, false, 0);
displayVBox->pack_start(*currDisplayLabel, false, false, 0);
displayFrame->set_name("displayFrame");
displayFrame->set_border_width(2);
displayFrame->set_label_align(0, 0);
displayFrame->set_shadow_type(GTK_SHADOW_ETCHED_IN);
displayFrame->add(*displayVBox);
...
// Here is where I set the background. I've tried setting the the frame bg
// color like this:
Gtk::Style *dispStyle = displayFrame->get_style();
Gdk_Color *color = new Gdk_Color("white");
dispStyle->set_bg(GTK_STATE_NORMAL, *color);
displayFrame->set_style(*dispStyle);

// I've also tried setting the bg color of the labels like this:
//Gtk::Style *histStyle = histDisplayLabel->get_style();
//Gtk::Style *currStyle = currDisplayLabel->get_style();
//Gdk_Color *color = new Gdk_Color("white");
//histStyle->set_bg(GTK_STATE_NORMAL, *color);
//currStyle->set_bg(GTK_STATE_NORMAL, *color);
//histDisplayLabel->set_style(*histStyle);
//currDisplayLabel->set_style(*currStyle);

Neither of these two methods worked for me. Can anyone tell me what I'm doing wrong? Thanks. -Jeff




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