Results 1 to 6 of 6

Thread: How to solve this problem about drawImage() and paintEvent()?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2013
    Posts
    56
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default How to solve this problem about drawImage() and paintEvent()?

    Hi, all
    I am working under linux with QT4.7, and my test code is like below:
    Qt Code:
    1. 12 void MyWidget :: paintEvent ( QPaintEvent * event )
    2. 13 {
    3. 14 init();
    4. 15 }
    5. 16
    6. 17 void MyWidget :: init()
    7. 18 {
    8. 19 QImage bg( width(), height(), QImage::Format_ARGB32_Premultiplied );
    9. 20 QImage a( width(), height(), QImage::Format_ARGB32_Premultiplied );
    10. 21 QImage b( width(), height(), QImage::Format_ARGB32_Premultiplied );
    11. 22
    12. 23 QPainter p;
    13. 24
    14. 25 p.begin( &bg );
    15. 26 QRect r = rect();
    16. 27 p.fillRect( r, Qt::white );
    17. 28 p.end();
    18. 29
    19. 30 p.begin( &a );
    20. 31 p.setPen( QPen( QColor( Qt::red ), 5 ) );
    21. 32 p.drawLine( 10, 10, 50, 50 );
    22. 33 p.end();
    23. 34
    24. 35 p.begin( &b );
    25. 36 p.setPen( QPen( QColor( Qt::green ), 5 ) );
    26. 37 p.drawLine( 10, 70, 50, 10 );
    27. 38 p.end();
    28. 39
    29. 40 p.begin( this );
    30. 41 p.drawImage( QPoint(0,0), bg );
    31. 42 p.drawImage( QPoint(0,0), a );
    32. 43 p.drawImage( QPoint(0,0), b );
    33. 44 p.end();
    34. 45 }
    To copy to clipboard, switch view to plain text mode 

    Then, at the beginning the widget is shown correctly - there are two lines cross with each other at the Top-Left corner, one is green and another is red. But when I drag the Bottom-Right corner of this widget to resize it, the two lines will be repainted in a wrong way. Why and how to solve it?

    Any suggestion is appreciated.

    Nicho
    Last edited by Nicho; 12th November 2013 at 06:16.

Similar Threads

  1. How to solve GUI freezing problem
    By honestapple in forum Newbie
    Replies: 28
    Last Post: 6th April 2013, 12:35
  2. Replies: 1
    Last Post: 20th July 2012, 16:38
  3. vary hard problem to solve
    By FS Lover in forum Newbie
    Replies: 3
    Last Post: 2nd July 2009, 09:26
  4. How to solve this cc1plus: out of memory problem?
    By triperzonak in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2008, 20:20
  5. Replies: 12
    Last Post: 3rd April 2006, 06:11

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.