bunny1985
bunny1985

Reputation: 772

Python gtk TextView border not working from css

I have really strange situation. From the gtk css style I can apply for example background color, order radius, but i cant make the border to be visible. The file is ultra simple:

GtkTextView  {

    border-radius: 3px;
    border-width: 1px 1px 2px 1px;
    border-style: solid;
    border-color: #000;
    /*background-color: #0000ff;*/
    }

What am I doing wrong ?

Upvotes: 1

Views: 770

Answers (2)

Rob
Rob

Reputation: 464

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.

Upvotes: 1

bunny1985
bunny1985

Reputation: 772

My system is Mint with cinnamon . I don't remember theme name by heart, but I think that I've tried two or three. In the end I have added a frame not a perfect solution but it works.

Upvotes: 0

Related Questions