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

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.

Related

Is it possible to create visual elements in PyQt6?

As my code is quite long and with a lot of nested layouts I won't put it in here but I essentially have a QHBoxLayout which I want to have a different background colour as the others. I First thought about changing the stylesheet but I quickly learned that the layout is not affected by that as it apparently is not a visual element. Hence my Question: How do I create simple (geometric) elements? Is it even possible to just have a colored box in the background and some lables and pictures in the foreground?
I tried just using a big QTextEdit block and colouring this with the StyleSheet but this didn't get me the results I hoped for as It'd be hard to align the text the way I want it to be and add pictures.

Placing a background image behind a semi-transparent table in wxPython

I'm trying to make a frame in wxPython using a wx.grid as a table and with a background image behind the cells.
I already tried placing the grid in a table and lowering the frame opacity with frame.SetTransparent(), which might work, but the frame just refuses to display if I give the parent a background with StaticBitmap. I couldn't find an alternative way to use an image as a background or a way to fix that problem.
There's also the wx.grid.SetDefaultCellBackgroundColour function, but the function only accepts RGB values with no alpha. I tried messing around with internal values but no luck there either.
Bonus points if the image doesn't overlap with the headers but at this point I'll take what I can get.

Need FULL transparency of ".png" file format

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.

Qt QScrollBar change background Color

I was working on Qt Designer and I wanted to edit the background color (if possible a gradient) of QScrollBar but I don't know how to do it properly.
When I add any background color the whole widget changes color uniformly and becomes solid.
I was trying to change the color of the area behind the bar and arrow buttons only.
Unfortunately, with many complex widgets you can't just change a property with stylesheet without all the necessary implementation.
QScrollBar is one of those widgets, and in order to achieve background customization through stylesheets, at least all the following have to be provided too:
overall background color
add/sub-page color
handle color
add/sub-line ("arrow buttons") colors
To make the widget more visually responsive, borders (with pseudo-states for pressed/enabled/hover states) should also be provided, and adding images for arrow buttons is usually suggested (small arrows can be obtained through css border tricks, though).
The starting point is the official Qt stylesheet example documentation, which has a section for customizing QScrollBar.
Note that using a QProxyStyle is not an option, as many styles draw scrollbars in different ways, and sometimes they even ignore some "official" style functions like drawControl, because they take care of the whole painting within the drawComplexControl, using private functions.

Send widgets content scaled to printer

I'm using QWidget.grab to get a pixmap containing what a component currently displays. It works perfectly apart from the size of the component not suitable for my printing requirements.
Is there a way so I can grab the pixmap of the component in a particular size?
QPixMap.grab() in Qt5 and QPixMap.grabWidget() in Qt4 get a pixmap of a painted widget in the screen resolution which is the natural painting resolution. Using the rectangle parameter you can even get parts of widgets.
The natural output resolution is the widgets own screen resolution. But afterwards you can scale it to anything you like via QPixMap.scaled() so that it fits your printing requirements.
It would actually be nice to change (simple scale) the painting resolution when grabing. But I don't know of any way to achieve this.

Categories