GNOME Bugzilla – Bug 663589
Gtk.Overlay Not Transparent
Last modified: 2011-11-08 20:19:44 UTC
I have been working with the new Gtk.Overlay object, and I was disappointed to discover that it does not work as it should. When any object is added via overlay.add_overlay(object), the background object (added via overlay.add(object) is completely hidden. My code is below. -- from gi.repository import Gtk, Gdk, GdkPixbuf, GdkX11 class OverlayTest: def __init__(self): win = Gtk.Window() win.set_resizable(False) win.set_decorated(False) win.set_size_request(640, 480) win.set_position(Gtk.WindowPosition.CENTER) overlay = Gtk.Overlay() win.add(overlay) overlay.show() pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("IMG/IMG-AMB-BRDG-L.png", 640, 480) img = Gtk.Image() img.set_from_pixbuf(pixbuf) overlay.add(img) img.show() fixed = Gtk.Fixed() overlay.add_overlay(fixed) fixed.show() pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("IMG/IMG-MPG-LOGO.png", 250, 50) imgMPL = Gtk.Image() imgMPL.set_from_pixbuf(pixbuf) eb_imgMPL = Gtk.EventBox() eb_imgMPL.set_visible_window(False) eb_imgMPL.add(imgMPL) fixed.put(eb_imgMPL, 10, 10) imgMPL.show() eb_imgMPL.show() win.show_all() if __name__ == "__main__": Gdk.threads_enter() OverlayTest() Gtk.main() -- How do I make this object function properly? Its functionality is pivotal to my project...in fact, it is the whole reason why I ported to PyGObject 3 in the first place.
You should simplify your testscript when asking help. There is way too much going on that is totally unnecessary and most of us probably won't have those image files :-). Anyway, here is a working example: from gi.repository import Gtk class OverlayTest: def __init__(self): win = Gtk.Window() win.resize(400, 100) win.connect('delete-event', Gtk.main_quit) overlay = Gtk.Overlay() label = Gtk.Label("See me?") overlay.add(label) label = Gtk.Label("I am the overlay label") label.set_halign(Gtk.Align.END) label.set_valign(Gtk.Align.END) overlay.add_overlay(label) win.add(overlay) win.show_all() if __name__ == "__main__": OverlayTest() Gtk.main() Docs are your friend: http://developer.gnome.org/gtk3/stable/GtkOverlay.html
If you look at my code, that is exactly what I have done. The reason I used the images is that the problem occurs with the images. And I did happen to read the documentation. Several times. That's how I got my above code in the first place. Replace my image file paths with something you have, and you'll see my problem. As far as I know, labels are a very different animal.
It works perfectly with images and your example (which uses a Gtk.Fixed to overlay, not image) as well. I think you missed the important bits in my example/docs: label.set_halign(Gtk.Align.END) label.set_valign(Gtk.Align.END)
Okay, that (mostly) works now. That wasn't super clear in the documentation, thus why I overlooked it. Docs could use a bit of polishing there... Last aspect is, the image I've overlayed appears to lose its transparency (it's a .png with an alpha channel). Is there any additional step I need to make to correct this? Transparency here is very important to my project.
Overlays look like a fairly new API which may not support alpha blending. I think that is what clutter is for. Not sure though. You should ask nacho who wrote the patch in #gtk on irc.
Any other bugs should be filed against Gtk
*** Bug 663417 has been marked as a duplicate of this bug. ***