Hi,

I would like to paint on a widget, but every time I call another function, it deletes the old widget content.

I already tried to create an instance of Pixmap with

Qt Code:
  1. pixmap = QPixmap(pixmap);
To copy to clipboard, switch view to plain text mode 

and removed fill() but this doesn't work.

Why is it possible to call

Qt Code:
  1. pixmap = QPixmap(size());
To copy to clipboard, switch view to plain text mode 

but not

Qt Code:
  1. pixmap = QPixmap(pixmap); ??
To copy to clipboard, switch view to plain text mode 

Here is the code snippet:

Qt Code:
  1. void ClientWindow::paintEvent(QPaintEvent * /* event */)
  2. {
  3. QStylePainter painter(this);
  4. painter.drawPixmap(0, 0, pixmap);
  5.  
  6. if (hasFocus()) {
  7. option.initFrom(this);
  8. option.backgroundColor = palette().dark().color();
  9. //painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
  10. }
  11. }
  12.  
  13. void ClientWindow::drawCircle(int x, int y, int width, int height)
  14. {
  15. pixmap = QPixmap(size());
  16. pixmap.fill(this, 0, 0);
  17.  
  18. QPainter painter(&pixmap);
  19. painter.initFrom(this);
  20.  
  21. pen.setStyle(Qt::SolidLine);
  22. pen.setWidth(3);
  23. pen.setBrush(Qt::green);
  24. pen.setCapStyle(Qt::RoundCap);
  25. pen.setJoinStyle(Qt::RoundJoin);
  26.  
  27. brush.setStyle(Qt::SolidPattern);
  28.  
  29. painter.setPen(pen);
  30. //painter.setBrush(brush);
  31.  
  32. if (antialiased)
  33. painter.setRenderHint(QPainter::Antialiasing, true);
  34. painter.drawEllipse(x, y, width, height);
  35. update();
  36. }
  37.  
  38. void ClientWindow::drawLine(int x1, int y1, int x2, int y2)
  39. {
  40. pixmap = QPixmap(size());
  41. pixmap.fill(this, 0, 0);
  42.  
  43. QPainter painter(&pixmap);
  44. painter.initFrom(this);
  45.  
  46. //...
To copy to clipboard, switch view to plain text mode