Results 1 to 2 of 2

Thread: paintEvent and Pixmap - not deleting old content!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default paintEvent and Pixmap - not deleting old content!

    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 

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: paintEvent and Pixmap - not deleting old content!

    I'm bit confused what you're trying to do here.

    Why you are drawing widget to pixmap?
    Why you are drawing in each function?

    Can't you cache the widget image once and then draw on top of it multiple times?
    If the content of the widget changes often, there's no point caching it.
    If the content doesn't change but your drawing do - then create separate cache for widget and separate for drawings and draw second on top of the first one.

    Like I said - I'm bit confused so you need to explain what you're trying to achieve bit better.

Similar Threads

  1. Replies: 1
    Last Post: 19th April 2011, 11:17
  2. QLabel and its content (pixmap) position problem.
    By miqqo in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2010, 09:57
  3. Deleting a thread content
    By Luc4 in forum Qt Programming
    Replies: 17
    Last Post: 21st April 2010, 08:39
  4. Save content of widget to pixmap
    By vql in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2008, 22:26
  5. QPainter ouside of paintEvent with a pixmap
    By bitChanger in forum Qt Programming
    Replies: 10
    Last Post: 22nd March 2006, 19:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.