Как добавить анимацию в уже отрисованный виджет PyQt5
Пытаю добавить третью анимацию, в уже запущенную программу, для этого использую методы родительского класса, self.update()
, self.repaint()
, но анимация не добавляется.
Что я делаю не так?
from PyQt5.QtCore import QTimer, QPropertyAnimation, QParallelAnimationGroup, QRect, QEasingCurve
from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QVBoxLayout
from PyQt5.QtGui import QPixmap
import sys
class Label(QLabel):
def __init__(self, parent=None):
super().__init__(parent)
#self.setFixedSize(400, 400)
self.setPixmap(QPixmap("icon.png"))
class Main(QWidget):
def __init__(self):
super().__init__()
self.timer = QTimer()
self.setFixedSize(400, 400)
self.i = 0
self.label = Label(self)
self.label.move(0, 0)
self.label2 = Label(self)
self.label2.move(0, 0)
self.animation1 = QPropertyAnimation(self.label, b'geometry')
self.animation2 = QPropertyAnimation(self.label2, b'geometry')
self.group = QParallelAnimationGroup(self)
self.group.addAnimation(self.animation1)
self.group.addAnimation(self.animation2)
self.timer.timeout.connect(self.move_label)
self.timer.start(1000)
def add_tag(self):
self.label3 = Label(self)
self.label3.move(0, 0)
self.animation3 = QPropertyAnimation(self.label3, b'geometry')
self.group.addAnimation(self.animation3)
self.animation3.setStartValue(QRect(self.label3.pos().x() + 20, self.label3.pos().y() +
30, 100, 30))
self.animation3.setEndValue(QRect(self.label3.pos().x() + 50, self.label3.pos().x() + 60,
100, 30))
self.animation3.setLoopCount(1)
#self.group.updateDirection()
def move_label(self):
self.i += 1
if self.i == 2:
self.i = 0
self.add_tag()
print(self.group.animationCount())
self.animation1.setStartValue(QRect(self.label.pos().x(), self.label.pos().y(), 100, 30))
self.animation1.setEndValue(QRect(self.label.pos().x() + 30, self.label.pos().y() + 40,
100, 30))
self.animation1.setLoopCount(1)
#self.animation1.setDuration(1000)
#self.animation1.setEasingCurve(QEasingCurve.OutBounce)
self.animation2.setStartValue(QRect(self.label2.pos().x(), self.label2.pos().y(), 100,
30))
self.animation2.setEndValue(QRect(self.label2.pos().x() + 40, self.label2.pos().y() + 50,
100, 30))
self.animation2.setLoopCount(1)
#self.animation2.setDuration(1000) # 8000
#self.animation2.setEasingCurve(QEasingCurve.CosineCurve)
self.group.start()
#self.label.move(self.point)
#self.label2.move(self.point2)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Main()
w.show()
sys.exit(app.exec_())