GTK drawable area transparent background color

陌路散爱 提交于 2019-12-08 10:43:59

问题


I have a GTK drawing area and I want to have an image display as the background for it, while other things can be drawn over it.

My first attempt at this involved me simply taking the image, putting it into a pixmap, and drawing it before I draw other objects. This resulted in the objects backgrounds completely covering my background image.

Now I am thinking I need to change the object's pixmap's gtk.gdk.GC so the background color it has is transparent. Here is where I am having problems. I do not know how to set a gtk.gdk.Color's alpha.

How do I set a gtk.gdk.Color's alpha? (or any other way of making the color transparent)

If this idea seems unlikely to work please let me know. I am pretty new to GTK.


回答1:


I don't know if this can help you, but my best advice is to use Cairo: an open source 2D graphics library providing cross-platform support for advanced 2D drawing. It is also the easiest way to draw 2D graphics, I think (I've tried GDK in the past and I thought it was much more tricky to use).

In python you can use the specific bindings Pycairo. Here you can learn more about it, with easy tutorials.

For your specific problem, see more about images and trasparency.

The main function for trasparency are:

  • set_source_rgba(red, green, blue[, alpha=1.0])

  • paint_with_alpha(alpha)

A great summary to learn how to manage images and transparency is in the example Reflected image in the same page linked before about trasparency.



来源:https://stackoverflow.com/questions/16843283/gtk-drawable-area-transparent-background-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!