class Circle(QGraphicsEllipseItem): def __init__(self, parent=None): super().__init__(parent) self.anim = QVariantAnimation() self.setRect(QRectF(-10, -10, 20, 20)) self.setPen(QPen()) def move_to(self, pos, duration=1000): if self.anim.state() == QAbstractAnimation.Running: self.anim.stop() self.anim.setStartValue(self.pos()) self.anim.setEndValue(pos) self.anim.valueChanged.connect(self.setPos) self.anim.setDuration(duration) self.anim.start() class View(QtWidgets.QMainWindow, Ui_MainWindow): def movee(self): for i in range(self.num_circles): self.circl_liste = Circle() for pa in dir(self.circl_liste): self.circl_liste.setBrush(self.blue_brush) self.circl_liste.Status = 'Not Sick' self.circl_liste.anim.finished.connect(lambda item=self.circl_liste: self.move_circles(item)) self.scene.addItem(self.circl_liste) self.move_circles(self.circl_liste) def move_circles(self, item): self.pos = QPointF(*random.sample(range(-150, 250), 2)) item.move_to(self.pos) def update_scene(self, circl_liste): for i in circl_liste: for k in circl_liste: if i.Status == 'Sick': self.scene.addEllipse(QRectF(self.circl_liste.x(), self.circl_liste.y(), 20, 20), self.pen, self.red_brush)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)