Results 1 to 5 of 5

Thread: how can i clear qpainter drawings

  1. #1
    Join Date
    Jul 2011
    Posts
    81
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default how can i clear qpainter drawings

    How can i clear all the drawings i have done with qpainter?

  2. The following user says thank you to athulms for this useful post:

    TheIndependentAquarius (15th March 2017)

  3. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: how can i clear qpainter drawings

    This is a little bit to little to know what you meant to ask I can just guess:

    Qt Code:
    1. void QPainter::eraseRect ( const QRectF & rectangle )
    To copy to clipboard, switch view to plain text mode 
    Don't write a post just to thank someone, use "Thanks" button.

  4. The following user says thank you to Rachol for this useful post:

    TheIndependentAquarius (15th March 2017)

  5. #3
    Join Date
    Jul 2011
    Posts
    81
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: how can i clear qpainter drawings

    Qt Code:
    1. void mainwindow::paintEvent(QPaintEvent *e)
    2. {
    3. painter=new QPainter(this);
    4. QPen linepen(Qt::red);
    5. linepen.setCapStyle(Qt::RoundCap);
    6. linepen.setWidth(25);
    7. painter->setRenderHint(QPainter::Antialiasing,true);
    8. painter->setPen(linepen);
    9. drawing(painter);
    10. }
    11. void mainwindow::drawing(QPainter *painter)
    12. {
    13. painter->drawLine(point,point2);
    14. timer3 = new QTimer(this);
    15. timer3->start(200);
    16. connect(timer3, SIGNAL(timeout()), this, SLOT(erase(QPainter *)));
    17. }
    18. void mainwindow::erase(QPainter *painter)
    19. {
    20.  
    21. painter->eraseRect(100,40,550,440);
    22. timer3->stop();
    23. }
    24. {
    To copy to clipboard, switch view to plain text mode 


    I have to erase the line i have drawn after 200ms. But this code doesnot work what can i do?

  6. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how can i clear qpainter drawings

    Quote Originally Posted by athulms View Post
    I have to erase the line i have drawn after 200ms. But this code doesnot work what can i do?
    Schedule an update after 200ms with a timer and don't draw the line in the paint event.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    TheIndependentAquarius (15th March 2017)

  8. #5
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: how can i clear qpainter drawings

    In my opinion the code example you have given should be fixed in many ways:

    1.You are creating new QPainter and QTimer objects every time you enter paintEvent method. That's a memory leak if you don't have it deleted.

    2. You should not draw a widget outside a paintEvent, what you are actually doing in the erase method.

    3. Is the connection you made actually working? It doesn't look correct to me.

    After getting rid off these errors, you shoud then use Wysota's tip.
    Don't write a post just to thank someone, use "Thanks" button.

  9. The following user says thank you to Rachol for this useful post:

    TheIndependentAquarius (15th March 2017)

Similar Threads

  1. QPainter(&QPrinter) & QPainter(&QImage) communication
    By gufeatza in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2010, 07:25
  2. Replies: 5
    Last Post: 7th September 2009, 20:57
  3. Can I save the drawings from QGraphicsScene?
    By learning_qt in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2008, 11:03
  4. Tracing Drawings
    By RY in forum Newbie
    Replies: 2
    Last Post: 10th September 2008, 13:44
  5. Replies: 3
    Last Post: 30th April 2006, 19:22

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.