Need FULL transparency of ".png" file format - python

I want a floating round button (no window-frame + no title bar + transparency) in my Python-project. For this I created a round button in GIMP (with transparency around the button). I am a beginner in GUI-programming therefore I will explain you all the steps I already tried so far:
First try: I tried to use Tkinter with this attributes:
self.configure(background='black')
self.wm_attributes("-topmost", 1)
self.wm_attributes('-transparentcolor', 'black')
This was a little success for me but I didn't like the jagged edges around:
the jagged edges were best visible on white backgrounds:
Second try: This time I used PyQt5 and at first glance everything was perfect and I used these settings:
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
But a closer look gave me this:
partly transparent grey/white background:
Now I need advice from an expert because I could not find any helpful tutorial or documentation for this problem.

Related

Creating a "Fill" command in tk inter

I am pretty new to Python and coding in general. I have been working on a program that is similar in nature to ms paint. So far, I've added the capabilities to create multi-colored rectangles, lines, ovals, and really any polygon.
I've been using the tkinter GUI. I've been wanting to add a fill command, but I'm kind of stuck as to how to start it. My idea for how it would work would be that it would check the color of the pixel the user is currently hovering over, then check up, down, left, and right for the same color in pixels. If it found that, it would change the color of those pixels (I guess by creating a really small rectangle object?). This would theoretically be able to fill an area. But, I really can't find anything on how to access the color of a pixel in tkinter.
I know the location is event.x and event.y for a specific event, but I can't find anything about pixel color. I don't really have any code written for it yet because I am unsure that tkinter can even access the color of a pixel and not just object colors.
Unfortunately, this isn't possible. I did some searching around, and found several other similar questions, but the general idea is that Tkinter does not support such a feature. It makes sense, considering that Tkinter is a GUI library.
I saw a suggestion somewhere, where an idea was proposed to create 1x1 rectangles using the Tkinter Canvas to basically mimic pixels. However, this method eventually leads into performance issues and lagging, so it's not really recommended either.
You may want to try exploring some other libraries to work together with Tkinter. You can keep the Tkinter GUI, but use an image manipulation library or something similar which integrates well with Tkinter, for the actual pixel drawing.

How to Create a Clickable Widget with a Dynamic surface area?

My objective is to make a small widget that changes shape considering a single value (bottom bar).
I made this shape variation with a drawPoligon inside a paintEvent:
https://i.gyazo.com/ecbe701c15c24f069101bbe17a6bbf93.mp4
This widget will act like a color picker:
(example)
however I still have some limitations I don't know how to pass through yet.
My question kinda boils around these 2 points:
1- Previously I used CSS Style sheets on my QtDesigner UI made widget to paint the background-color, however I need to:
mask color sections of the widget
make it "unclickable" outside that area
paint the area with a polygonal shape that I can adjust the points.
2- I have used self.setMask() but it does not seem to affect the style sheet background color. if it does I do not know how to set it up properly. I also did attempts with clip_path and background-clip with poor or no results.
I have tryed with the drawPolygon shape I made but It creates a issue with the alpha of the SVG cursor I have. leaving a trail on the drawn Polygon until I update it again. if this is the way I would need a way to handle this issue to go around it.
I made a custom polygon that does the weird behavior on the video this is just a sample one on the example.
What I got so far:
background-color: rgb(85, 170, 127);
clip-path:polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
Thank you for any help in advance.

write antialiased text with custom font on transparent image

so, as the topic says, I want to write some text on an transparent image.
Or, to be more specific, I want to write on multiple specific positions different text. The point is, I want to use a custom font (coolvetica) and (and there is my problem) I want it to be anti-aliased. unfortunately, PIL does not support font-anti-aliasing, as you might already know, but also see here:
PIL example image.
So as you see, PIL has not only an issue with the coordinates, but also does not really support font-anti-aliasing and adds some irritating black-ish border to the text. It is not very usable for me.
So after some searching, I found Python Wand. The output is a lot better, but the antialiasing leads not to the result I want: Wand example image. The curves are not as smooth as I want and there are some weird "pimples" like the dot at the end of the "r".
My code to use wand is this:
with Drawing() as draw:
with wandimage(filename="Skispringen_Score.png") as img:
draw.font_family = 'coolvetica.ttf'
draw.text_antialias = True
draw.fill_color = (Color("rgba(255, 255, 255, 255)"))
for postionName, scorePosition in scoreContent.items():
if isinstance(currentScoreText[postionName], int) and currentScoreText[postionName] > 9:
center = 2
else:
center = 0
draw.font_size = fontsize[scorePosition["size"]]
draw.text(scorePosition["x"] - center, scorePosition["y"], str(currentScoreText[postionName]))
draw(img)
img.save(filename='wand-image.png')
And here is an example of what the text should actually look like: PHP example image.
This image was generated with php and the text looks as smooth as I want to.
I also tried to use cairo, but the documentation is really not that good (especially examples are rare) and I just don't even know how to write any text with it nor how to set an custom font.
The actual output image has an resolution of 1280x720 and is - besides of the text - completely transparent, the image is just an overlay for an videostream.
Do you have any idea how to get a nice looking text onto the image with python?
You could try pycairo. Here are some code examples https://github.com/pygobject/pycairo/tree/master/examples
The reference docs for cairo are for C.
If you want even better results then you could render the image at 4 times the size and
downsample it to the desired size.
You can also try some filters like a gaussian blur.
For pixel perfect images you will have to use the same rendering engine that your php function is using.

tkinter making background image as semi-transparent under all widgets

First image:
Second image:
The first image shows what I'm getting at this moment.
But I just want to make it as the 2nd image which is looking transparent for all widgets. Apparently tkinter widgets does not support transparency. How can I make my GUI like second image?
Any help would be appreciated.
I know question is asked long ago, but I(and probably still many beginners like myself) was bothered with same thing and I came up with some kind of solution.
I've just cut part of background of exact place where button is placed with exact measurements and I achieved something similar to transparency by placing that cropped image as background of a button, label....
Not a "coded" solution but worked for me.

What is the best practice to overlay a Phonon.VideoWidget?

The last couple of days I have tried to find a working solution to overlay a Phonon.VideoWidget with a simple QLabel. Sadly I wasn't able to find a working solution.
Here is what I have tried:
Parenting. I tried the "normal" parenting stuff addressing the QLabel to the VideoWidget. Result: The label does not show up at all.
QStackedLayout. As suggested here: http://www.qtcentre.org/threads/31490-Overlaying-Widgets-on-top-of-VideoWidget. Result: Label is shown but always behind the video
GraphicsView. I tried a lot here as it looked like the most promising, but at the end the CPU load was just too high so the video did not play back. Setting the view's viewport to QGLWidget did not solve it. Result: Overlay works but video does not play caused by high CPU load.
Subclassing the VideoWidget. As mentioned here: https://wiki.qt.io/Overlay_widget_for_Phonon_VideoWidget. I took the same approach to create the overlay. This works just fine after all, except for the moveEvent. It does not look nice if the label is realigned after moving the widget has finished. Is there a way to update this already when moving VideoWidget?
I really hope someone can help me here (I use PySide but examples in C++ should work as well) or give me a pointer on where to look. Please let me know if I should share some code snippet to reproduce.
The best you can do is creating a new window that floats above your video widget. For example create a parentless QLabel and make sure that it moves in sync with your main window.
label = new QLabel();
label->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
In your QMainWindow subclass, override moveEvent and resizeEvent and do something like:
label->move(mapToGlobal(QPoint(0, height() - label->height())));
This keeps the label in the bottom-left corner, change it to fit your needs.

Categories