You have not specified the programming language, so I assume Python for simplicity reasons.
In gtk, most components can connect to an expose event which can then be used to draw manually into the widget (cairo is used for this, all those widgets have a cairo context attached to them)
Here is a simple example of a window with a custom colored Vbox and two buttons, the space between the bottons (here set to 20 pixels) and the small border around the buttons shows the background color of the VBox.
import gtk
class MyColoredBox(gtk.VBox):
def __init__(self, homogeneous=False, spacing=0):
super(MyColoredBox, self).__init__(homogeneous, spacing)
self.connect("expose-event", self.expose)
def expose(self, widget, event):
cr = widget.window.cairo_create()
cr.set_source_rgb(1.0, 1.0, 0.5)
cr.rectangle(event.area.x, event.area.y,
event.area.width, event.area.height)
cr.fill()
class PyApp(gtk.Window):
def __init__(self):
super(PyApp, self).__init__()
self.connect("destroy", gtk.main_quit)
vbox = MyColoredBox(False, 20)
b1 = gtk.Button("Hello")
b2 = gtk.Button("World")
vbox.add(b1)
vbox.add(b2)
self.add(vbox)
self.show_all()
if __name__ == "__main__":
PyApp()
gtk.main()
The resulting programm looks something like this:
