title: Repainting widgets in QT
body: <p>I have a piece of code that initializes an instance of a QWidget, puts it inside a layout and invokes the animation. All of that is happening in the loop. I've encountered a problem of each iteration drawing the animation at the same time, completely ignoring QThread::usleep(). Is there a way to clean the layout the proper way so that I could achieve desired result?</p>
  
  <pre><code>double randomTestArray[numOfPoints];
  double fMin = 0;
  double fMax = 20;
  srand(time(NULL));
  for(int p = 0 ; p &lt; 100 ; p++)
  {
      Equalizer * eq = new Equalizer();
      ui-&gt;verticalLayout-&gt;addWidget(eq);
      for(int i = 0 ; i &lt; numOfPoints ; i++)
      {
          randomTestArray[i] = fMin + (double)rand() * (fMax - fMin) / RAND_MAX;
      }             
      eq-&gt;setChunk(&amp;randomTestArray[0] , &amp;startArray[0]);
      ui-&gt;verticalLayout-&gt;removeWidget(eq);
      delete eq;
      QThread::usleep(1000);
  }
  </code></pre>
  
  <p>Animation is accomplished using QPropertyAnimation and paintEvent() in setChunk() method. Notify me if you're going to need any more code.</p>
  
  <p>Adding breakdown of Equalizer class :</p>
  
  <pre><code>void Equalizer::setChunk(double *chunk, int * startYArr)
  {
  
  if(*startYArr == -1)
  {
      for(int i = 0 ; i &lt; 24 ; i++)
      {
          *(startYArr + i) = 150;
      }
  }
  
  int xCoordinateArray[24];
  int yCoordinateArray[24];
  
  for(int i = 0 ; i &lt; 24 ; i++)
  {
      yCoordinateArray[i] = *(chunk + i) * 5;
      xCoordinateArray[i] = 100 + i*25;
  }
  
  cout &lt;&lt; "Chunk initialized" &lt;&lt; endl;
  cout &lt;&lt; "Start Coordinates : " &lt;&lt; endl;
  for(int i = 0 ; i &lt; 24 ; i++)
  {
      cout &lt;&lt; startYArr[i] &lt;&lt; endl;
  }
  cout &lt;&lt; "End Coordinates : " &lt;&lt; endl;
  
  for(int i = 0 ; i &lt; 24 ; i++)
  {
      cout &lt;&lt; yCoordinateArray[i] &lt;&lt; endl;
  }
  
  QPropertyAnimation *animation = new QPropertyAnimation(this , "nrect");
  animation-&gt;setDuration(2000);
  animation-&gt;setStartValue(QRect(xCoordinateArray[0] , *(startYArr + 0) , 10 , 10));
  animation-&gt;setEndValue(QRect(xCoordinateArray[0] , 150 - yCoordinateArray[0] , 10 , 10));
  animation-&gt;start();
  connect(animation, &amp;QPropertyAnimation::valueChanged , [=](){update();});
  
  QPropertyAnimation *animation2 = new QPropertyAnimation(this , "nrect2");
  animation2-&gt;setDuration(2000);
  animation2-&gt;setStartValue(QRect(xCoordinateArray[1] , *(startYArr + 1), 10 , 10));
  animation2-&gt;setEndValue(QRect(xCoordinateArray[1] ,  150 - yCoordinateArray[1] , 10 , 10));
  animation2-&gt;start();
  connect(animation2, &amp;QPropertyAnimation::valueChanged , [=](){update();});
  
  QPropertyAnimation *animation3 = new QPropertyAnimation(this , "nrect3");
  animation3-&gt;setDuration(2000);
  animation3-&gt;setStartValue(QRect(xCoordinateArray[2] , *(startYArr +2) , 10 , 10));
  animation3-&gt;setEndValue(QRect(xCoordinateArray[2] ,  150 - yCoordinateArray[2] , 10 , 10));
  animation3-&gt;start();
  connect(animation3, &amp;QPropertyAnimation::valueChanged , [=](){update();});
  ................................
   for(int i = 0; i &lt; 24 ; i++)
  {
      *(startYArr + i) = yCoordinateArray[i];
  }
  
  
  void Equalizer::paintEvent(QPaintEvent *event)
  {
  Q_UNUSED(event);
  
  QRect ellipse(mRect);
  QPainter painter(this);
  painter.setBrush(Qt::red);
  painter.drawEllipse(ellipse);
  
  QRect ellipse2(mRect2);
  painter.setBrush(Qt::red);
  painter.drawEllipse(ellipse2);
  
  QRect ellipse3(mRect3);
  painter.setBrush(Qt::red);
  painter.drawEllipse(ellipse3);
  .............................
  </code></pre>
  
  <p>Attempted solution : </p>
  
  <pre><code>eq-&gt;setChunk(&amp;randomTestArray[0] , &amp;startArray[0]);
  QCoreApplication::processEvents();
  ui-&gt;verticalLayout-&gt;removeWidget(eq);
  QThread::usleep(1000);
  </code></pre>