Search code examples
monomonodevelopgtk#

Gtk.Viewport background transparency


I'm building an application that displays a list of business objects within a Gtk.ScrolledWindow widget. This stuff works like a charm with one exception.

Since I'm using a background image I would like the Gtk.Viewport within the ScrolledWindow to be transparent (or is it the ScrolledWindow that draws a white background?) so that the background image would be visible.

I've already googled a lot but couldn't find any working solution but I stumbled accross a post that mentioned that Viewport instances should already be transparent?!

I'm using MonoDevelop 5.10.3 and Gtk# for .Net 2.12.30. Is this a known issue and is there any way to fix this?

Thx for any help


Solution

  • Since Gdk.Color doesn't support alphas this is not straight forward. You could try using Cairo to do it, as this support alphas, if you hook into the expose event of the widgets that are hiding your background image, something like the following?

    protected void aWidget_ExposeEvent (object o, ExposeEventArgs args)
    {
        using (Cairo.Context _cc = CairoHelper.Create (args.Event.Window)) {
            _cc.SetSourceRGBA (1, 1, 1, 0);
            _cc.Rectangle (0, 0, <WIDTH>, <HEIGHT>);
            _cc.StrokePreserve ();
            _cc.Fill ();
        }
    }
    

    Where WIDTH and HEIGHT are the size of the area you want to be clear. Hope this helps! Good luck.