Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i work on this project and i did moving random circles. after a while some of them will change the color and keep moving. I tried to do it in the method update_scene using add_Ellipse but they are not moving and i didn't understand why. I am new in Python so please be kind. thank you

What I have tried:

Python



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)
Posted
Updated 25-Feb-21 10:59am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900