title: how to avoid paintevent() being called when the widget was obscured and uncovered
body: <p>i want to draw some rhombuses with random colors in a <code>Qwidget</code>. The widget should be repainted only when the window is resized .The problem is that when the widget was obscured and has now been uncovered , it is repainted. How can i avoid calling <code>paintEvent()</code> in this case? Thanks in advance.</p>
  
  <pre><code>void Dialog::paintEvent(QPaintEvent *e)
  {
      QPainter painter(this);
      QRect background(0,0,this-&gt;geometry().width(),this-&gt;geometry().height());
  
      painter.setBrush( QBrush( Qt::white ) );
      painter.setPen( Qt::NoPen );
      // QBrush bbrush(Qt::black,Qt::SolidPattern);
      painter.drawRect(background);
  
      int width = this-&gt;geometry().width();
      int height = this-&gt;geometry().height();
      int rec_size=64;
      int rows=floor((double)height/(double)rec_size);
      int cols=floor((double)width/(double)rec_size);
  
      QPointF points[4];
  
      for (int i=0;i&lt;floor(rows);i++)
      {
          for (int j=0;j&lt;floor(cols);j++)
          {
              painter.setBrush( QBrush( colors[rand() % color_size] ) );
  
              points[0] = QPointF(rec_size*(j),rec_size*(i+0.5));
              points[1] = QPointF(rec_size*(j+0.5),rec_size*(i));
              points[2] = QPointF(rec_size*(j+1),rec_size*(i+0.5));
              points[3] = QPointF(rec_size*(j+0.5),rec_size*(i+1));
  
              painter.drawPolygon(points, 4);
          }
      }
  }
  </code></pre>