How can I make the animation to rotate a widget in PyQt5?

25 Views Asked by At

I want to convert the anim_2 into a rotation but I don't know how or even if it's possible. I tried to use the QPropertyAnimation with (b"angle") but it don't do nothing. Any help or idea? Thanks!

import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(600, 600)
        self.child = QWidget(self)
        self.child.setStyleSheet("background-color:red;border-radius:15px;")
        self.child.resize(100, 100)
        self.anim = QPropertyAnimation(self.child, b"pos")
        self.anim.setEndValue(QPoint(200, 200))
        self.anim.setDuration(1500)
        self.anim_2 = QPropertyAnimation(self.child, b"angle")
        self.anim_2.setStartValue(90)
        self.anim_2.setEndValue(270)
        self.anim_2.setDuration(2000)
        self.anim_2.setLoopCount(-1)
        self.anim_group = QSequentialAnimationGroup()
        self.anim_group.addAnimation(self.anim)
        self.anim_group.addAnimation(self.anim_2)
        self.anim_group.start()


app=QApplication([])        

MW=Window()
MW.show()

app.exec_()
0

There are 0 best solutions below