eric’s extremeboredom

adventures into and out of extreme boredom.

Changing a Gtk# widget’s background color

This is one of those things that isn’t really documented very well anywhere so I figured I’d post it up here so people searching google find it.

Some widgets, like a label or frame, are “window-less”. I don’t have any idea what this means other than you cannot change their background color independently of their parent. To get around this, put them inside of an EventBox (in glade, right-click on the widget in the Widget Tree window and select “Add Event Box”) then set the color on this instead:

/* This will cause every windowless widget inside this eventbox
to have a white background */
eventbox2.ModifyBg(StateType.Normal, new Gdk.Color(0xff,0xff,0xff));

Another useful thing to note is that if you place another eventbox inside (as one of the widgets in a VBox, etc.) of here it will be painted using the system’s background color, so this is a simple way to have child widgets “revert” their background color back.

References:


Categorized as Technology/Software Development, Technology

1 Comments

  1. Thanks, I’ve been trying to find this out for some time!

    Allen

Leave a Reply