QPainter crashes while using the QPropertyAnimation - pyqt

I want to use the graphicsOpacityEffect in propertyAnimation for a QFrame that contains a label with a pixmap. My code is:
eff = QGraphicsOpacityEffect(frame)
widget.setGraphicsEffect(eff)
animation = QPropertyAnimation(eff, b"opacity")
animation.setStartValue(0)
animation.setEndValue(1)
animation.setDuration(500)
animation.setEasingCurve(QEasingCurve.InBack)
animation.start(QPropertyAnimation.DeleteWhenStopped)
Everything works, but when I hover the label, then the images disappear and I get the warning as below:
QPainter::setWorldTransform: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::translate: Painter not active
QPainter::worldTransform: Painter not active
QWidgetEffectSourcePrivate::pixmap: Painter not active
QPainter::worldTransform: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.

You should delete previously set QGraphicsOpacityEffect to the widget as follow before assigning new QGraphicsOpacityEffect to widget or its child:
connect(animation,&QPropertyAnimation::finished,[=](){
eff->deleteLater();
});
As the error says:
QPainter::begin: A paint device can only be painted by one painter at a time.
There are two or more painter trying to paint widget at same time.
Background:
QGraphicsEffect is the base class of QGraphicsOpacityEffect and for any graphics effects library in Qt. If you look into QGraphicsEffect source it uses QPainter for drawing. Hence user using any of graphics effects class on any widget implies he is initiating one QPainter to render effects and its obvious that we cannot draw using more than one QPainter at a time on a device or surface.

Related

Pygame - Changing shape/moving Collision Rect. for the sprite

I have a pygame sprite animation where the position and shape of the sprite changes throughout a certain animation sequence (eg. - attack). How do I adjust the sprite's rect for collisions?
My Image: in one part of the animation, my sprite is at the center of a png image file (96x64 pixels). In another part of the animation, my sprite is near the right side of the png image file (96x64 pixels). In another part of the animation, the sprite changes shape (caused by sword movement). Etc.
Do I have to do some math and calculation to adjust the collision rect. of the sprite each frame of the animation or is there an easier method?
I am new to pygame so I'm not sure of all the different features and am not sure where to begin with creating the different rects. for each frame.
PS. I am using a ready-made sprite I found online - each frame is 96x64 pixels in dimension
Frame 1, 11, 22:
It's been a while since I've worked with Pygame but I believe you can use a pygame.mask object. A mask is basically an object with the precise outline of the foreground of an image. It takes considerably more computation power but if you only create a mask for the one main character then it should be okay.
You can create a mask from the image:
myMask = pygame.mask(myImage)
Then you can either use its rect or create a new surface to use:
myRect = myMask.get_rect() # Returns the pygame.Rect object that conatains mask, or:
mySurface - myMask.to_surface() # Returns a pygame.Surface object of the mask
Hope this helps, my info is from:
https://www.pygame.org/docs/ref/mask.html

Canvas background color not saved

Tkinter canvas.postscript is not saving the canvas background.
Sizes of the canvas that are used throughout the Python code:
w = 800
h = 600
Function to be assigned to "SAVE CANVAS' button:
def save_canvas():
canvas.update()
canvas.postscript(file= r'Z:\\...\FILE.ps', height=h, width=w, colormode='color')
When I click on the button that has the save_canvas command assign, the file that is saved has no background as assigned in the widget. I changed the color to orange, green, etc. draw on it. Everything looks ok, but saving is without background. Same with .jpeg/.png
What do I need to call for saving the background? I'll be needing this as the application I build require images as background as well.
I don't believe the postscript command is designed to preserve the background color of the canvas widget. It only saves the items that appear on the canvas.
A simple solution is to draw a rectangle that is the exact size of the canvas, and change the color of that rectangle.

How to completely cover Xbox UWP 'current app' tile on homescreen?

Defining a splashscreen for a Xbox universal application leads to the following result:
The source of the image is a 1240x600 *.jpg which has a yellow border to indicate the edges of the image. The user who is currently logged in on the Xbox has red as his main color, leading to the red background behind the splashscreen.
I expected the splashscreen image to completely fill the 'current app' tile on the homescreen and not having this additional red background.
Is the latter the intended behaviour or is there a different image I can supply to completely cover this section on the homescreen?
The background is mandatary. A difference path you can take is define a background color of your tile, and use image with transparent color (png) as it will provide better UI.

Without alpha path how to decrease edge effect while paste icon

I got a RGB332 LCD and a poor MCU to drive it . The MCU do not have a hardware accelerator nor do RGB332 display support an alpha path.
So I used the color "black" as a "alpha color" to deal with icon paste work.Which means I fill the icon color data to background buffer while the data is not black.
The problem I meet is that the icon showed it's own antialiased edge while the background is not black. And the "antialiased edge" just makes an edge effect from the background.
Is there any way to deal with the situation ?
The main problem is that I don't have "Layer" and "Alpha" to do the PS-like merge work.
But the Icons are Pasted to a Frame buffer one by one.
So my solution is :
When each icon is being pasted,I could decide the front/background,
which means I could detect the "antialiased edge" of the icons just
like I have "layers".
After I find the antialiased edges ,I filled the pixels with the
middle color of the front/background.
The LCD is RGB332,and the middle color calculation is just filling
the edge with 75% background color + 25% front color. If the icon
color is carefully designed, you don't even need a float calculation
.
The work maybe not that effective ,but really solved my problem.

How to ensure graphics size change with change in window size?

I am drawing a rectangle in a picturebox. when the user manually changes the window size the rectangle size does not change. how do i make it resize?. i am drawing in the Paint event Thanks a lot

Resources