Results 1 to 6 of 6

Thread: Error while redrawing using QPainter Class

  1. #1
    Join Date
    Jul 2009
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Error while redrawing using QPainter Class

    Hi All,

    I am using QPainter class to draw line on the button event.
    I am using three push button on which every button different layouts of the line will draw.

    First time it works well but when I press rapidly few times then overwriting will occur.
    I am using painter.eraseRect(0,0,281,191); but it not works

    Can anyone help me to clear the label everytime when I draw.
    In Qt there is no painter.clear() properties.

    How can I clear the screen every time before I draw.

    Qt Code:
    1. In 1st Push button I write
    2.  
    3. QPixmap pix(281,191);
    4. QPen Pen((QColor::QColor (255,255,255,255)),2);
    5.  
    6. QLineF line1(0,50,281,50);
    7. painter.eraseRect(0,0,281,191);
    8. painter.begin(&pix);
    9. painter.setPen(Pen);
    10. painter.drawLine(line1);
    11. painter.end();
    12.  
    13. In 2nd button I write
    14.  
    15. QPixmap pix(281,191);
    16. QPen Pen((QColor::QColor (255,255,255,255)),2);
    17. QLineF line1(60,50,281,50);
    18. QLineF line2(60,141,281,141);
    19. QLineF line3(60,0,60,191);
    20. painter.eraseRect(0,0,281,191);
    21. painter.begin(&pix);
    22. painter.setPen(Pen);
    23. painter.drawLine(line1);
    24. painter.drawLine(line2);
    25. painter.drawLine(line3);
    26. painter.end();
    27.  
    28. so on..
    To copy to clipboard, switch view to plain text mode 
    Last edited by sosanjay; 16th December 2009 at 09:02.

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

    Default Re: Error while redrawing using QPainter Class

    You don't have to clear the label. Qt will auto-erase its contents before every 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.


  3. #3
    Join Date
    Jul 2009
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Error while redrawing using QPainter Class

    I am sending you the image Please check it.

    Initially it display correct but after clicking few times some default color comes.

    How can I solve this?

    Thanks for Reply.
    Attached Images Attached Images
    Last edited by sosanjay; 16th December 2009 at 11:12.

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

    Default Re: Error while redrawing using QPainter Class

    Please provide a minimal compilable example reproducing the problem.
    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.


  5. #5
    Join Date
    Jul 2009
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Error while redrawing using QPainter Class

    Hi wysota,

    I am sending you the sample code of drawline. Please check it I am trying lot to solve but I did not get the error.

    I am using clear(); clearMask(); for clearing the label but unwanted lines comes.

    In sample code there is four push button and according to button line will be drawn.
    Initially it display according to the code but when I press rapidly 40-50 times then unwanted line comes.

    Thanks in advance.
    Attached Files Attached Files

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

    Default Re: Error while redrawing using QPainter Class

    Fill the pixmap with transparency (or whatever other colour you want) before you start drawing on it.

    Qt Code:
    1. QPixmap pix(...,...);
    2. pix.fill(Qt::transparent);
    To copy to clipboard, switch view to plain text mode 
    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:

    sosanjay (29th December 2009)

Similar Threads

  1. How to drawline in a QWidget or any onther?
    By yangyunzhao in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2009, 08:19
  2. Correct way to clear a form?
    By Walter in forum Newbie
    Replies: 7
    Last Post: 16th August 2009, 19:54
  3. QLineEdit: with builtin clear button, how to
    By chezifresh in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2009, 21:05
  4. Replies: 1
    Last Post: 14th May 2008, 20:35
  5. QTextBrowser Clear selection
    By sreedhar in forum Newbie
    Replies: 2
    Last Post: 4th April 2006, 09:23

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.