Also banged my head on this one for too many hours - much longer and might have broken google. BTW: CSS borders don't work at all for this.
But it can be done by the Drawn signal.
Below code is C# (I'm not into python) but its short and 'll show the gist of it.
// add callback to Drawn signal handler
MyTextView.Drawn += widgetDrawn; // where you build your form / set up your widget
....
// this works on any widget, labels and containers included
private void widgetDrawn(object sender, DrawnArgs e)
{
e.Cr.SetSourceRGB(1, 0, 0); // red - so ya won't miss it.
e.Cr.Rectangle(0, 0, ((Widget)sender).Allocation.Width, ((Widget)sender).Allocation.Height);
// thicker line --> e.Cr.LineWidth = 1; // ... default is 1
e.Cr.Stroke();
}
- It works on any widget including labels and containers
- the RGB is Cairo style (double prec.) 0.0000..1.0), i.e. light grey: (0.828, 0.828, 0.828)
- the line is drawn inside the allocated widget area (i.e. the wider you make
LineWidth
the less area left inside for your widget's contents.
- clipping is all taken care of (i.e. overlapping / beyond window borders)
NOTE: if instead you're overriding (inherited class or similar) with: protected override bool OnDrawn(Cairo.Context cr) { ... }
-- call base.OnDrawn(cr)
before you add the border,
-- and be sure to return the bool result.