Как удалить все анимации из группы, но оставить саму группу

Я хочу запустить анимацию с разным содержимым

    self.group = QtCore.QSequentialAnimationGroup(self)
def anim(self):
    if X == True:
        self.group.addAnimation(self.animation_1)
        self.group.addAnimation(self.animation_2)
    elif X == False:
        self.group.addAnimation(self.animation_3)
        self.group.addAnimation(self.animation_4)
    self.group.start()
    self.group.clear()

Но проблема в том что если я использую clear() то после программа пишит

RuntimeError: wrapped C/C++ object of type QVariantAnimation has been deleted

Единственный способ который я знаю это

def anim(self):
    self.group = QtCore.QSequentialAnimationGroup(self)
    if X == True:
        self.group.addAnimation(self.animation_1)
        self.group.addAnimation(self.animation_2)
    elif X == False:
        self.group.addAnimation(self.animation_3)
        self.group.addAnimation(self.animation_4)
    self.group.start()
    self.group.clear()

Но можно ли это как то сделать не создавая постоянно новый AnimationGroup?

Update Я смог удалять старые анимаций используя self.group.removeAnimation(self.group.animationAt(0))

Но теперь почему-то анимация стала резкой

введите сюда описание изображения

Мой код

import sys

from PyQt5 import QtWidgets, QtGui, QtCore




class Rad(QtWidgets.QWidget):
    def __init__(self, group, pos, parent=None):
        super(Rad,  self).__init__(parent)
        self.resize(50, 50)

        lay = QtWidgets.QVBoxLayout(self)

        self.radio = QtWidgets.QRadioButton()
        self.label = QtWidgets.QLabel()
        self.label.setText('but-{}'.format(pos))

        self.group = group
        self.pos = pos
        lay.addWidget(self.radio)
        lay.addWidget(self.label)

        self.radio.toggled.connect(self.fun)

        self.animation = QtCore.QVariantAnimation() 
        self.animation.setDuration(1000)  
        self.animation.valueChanged.connect(self.value)
        self.animation.setStartValue(100)
        self.animation.setEndValue(0)

        self.can = False

    def value(self, val):
        self.move(self.pos, val)

    def fun(self):

        self.animation.setStartValue(
            100
            if not self.can 
            else 0
        )
        self.animation.setEndValue(
            0
            if not self.can 
            else 100
        )


        if self.group.animationAt(1) == None :
            print("Bad")
        else :
            print("Good")
            self.group.removeAnimation(self.group.animationAt(0))

        self.group.addAnimation(self.animation)

        self.group.start()


        self.can = not self.can





class Test(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.group = QtCore.QSequentialAnimationGroup(self)
        self.buts = QtWidgets.QButtonGroup(self, exclusive=True)
        wid_1 = Rad(self.group,   200, self)
        wid_2 = Rad(self.group,  100, self)
        wid_3 = Rad(self.group,  0, self)
        self.buts.addButton(wid_1.radio, 0)
        self.buts.addButton(wid_2.radio,1)
        self.buts.addButton(wid_3.radio, 2)
        wid_1.setStyleSheet('background:brown;')
        wid_2.setStyleSheet('background:yellow;')
        wid_3.setStyleSheet('background:green;')








if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    w = Test()
    w.resize(500, 500)
    w.show()
    sys.exit(app.exec_())

Ответы (0 шт):