Hi,
I have a strange problem. I have custom qlabel with a new paintevent function. This function will paint and connect points on a QLabel image. So far so good. This works, when I only use one label.

But if I create another label or copy the code and rename "RenderArea" to "RenderArea2", it is not working. Painting inside the first label also paints in the second label. If I raise another window, e.g. taskmanager, the application crashed. Really weired.

I hope you can understand my problem. Thanks.

Qt Code:
  1. class RenderArea : public QLabel {
  2. Q_OBJECT
  3.  
  4. public:
  5. RenderArea(QWidget *parent = 0);
  6.  
  7. protected:
  8. void paintEvent(QPaintEvent *event);
  9.  
  10. private:
  11. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void RenderArea::paintEvent(QPaintEvent *event)
  2. {
  3. QPainter painter(this);
  4.  
  5. painter.setRenderHint(QPainter::SmoothPixmapTransform, true );
  6. painter.setRenderHint( QPainter::Antialiasing, true);
  7. painter.fillRect(event->rect(), QBrush(Qt::white));
  8. painter.translate(30, 30);
  9. painter.save();
  10. painter.restore();
  11.  
  12. QPen pen;
  13. pen.setColor(Qt::green);
  14. pen.setWidth(4);
  15. pen.setJoinStyle(Qt::RoundJoin);
  16. pen.setCapStyle(Qt::RoundCap);
  17. painter.setPen(pen);
  18. QPoint p;
  19. p.setX(globalX-30);
  20. p.setY(globalY-30);
  21.  
  22. for(int i=0; i<pValues.count();i++)
  23. {
  24. painter.drawPoint(pValues.at(i));
  25. if(i > 0)
  26. {
  27. if(pValues.at(i).x() == pValues.at(i-1).x() && pValues.at(i).y() == pValues.at(i-1).y())
  28. {
  29. i++;
  30. }
  31. else
  32. {
  33. painter.drawLine(pValues.at(i-1), pValues.at(i));
  34. }
  35.  
  36.  
  37. }
  38.  
  39. }
To copy to clipboard, switch view to plain text mode 

pValues just stores the painted points so I can repaint them. The strange thing is that the paintevent from label1 paints also the in label2!
I also get the error message "QWidget::repaint: Recursive repaint detected".