Results 1 to 3 of 3

Thread: QPainter reuse within a paintEvent

  1. #1
    Join Date
    Jun 2007
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QPainter reuse within a paintEvent

    Is it possible/wise to re-use a QPainter within the paintEvent message? Something like...

    Qt Code:
    1. MyWidget::paintEvent( QPaintEvent *event )
    2. {
    3.  
    4. QPainter painter;
    5.  
    6. painter.begin( m_pixmap );
    7. painter.initFrom( this );
    8. painter.some_painting_stuff();
    9. painter.end();
    10.  
    11. painter.begin( this );
    12. painter.initFrom( this );
    13. painter.some_painting_stuff();
    14. painter.end();
    15. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPainter reuse within a paintEvent

    And why cant u use it like -
    Qt Code:
    1. MyWidget::paintEvent( QPaintEvent *event )
    2. {
    3. QPainter painter(this);
    4. painter.drawPixmap(,,,,,,);
    5. painter.some_painting_stuff1();
    6. painter.some_painting_stuff2();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Is there some problem or restriction in doing so ??

  3. #3
    Join Date
    Jun 2007
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QPainter reuse within a paintEvent

    Because for some odd reason, I had it in my head to create the pixmap within the paintEvent, then display it with the new painter(this) painting on the widget. Of course I have code that detects when the pixmap needs to be redrawn. 99% of the time it doesn't need to be redrawn so it should just copy the previous one onto the widget.

    I was having some weird problems and I wanted to know if what I was doing was ok.

    I have since changed the code around to generate the pixmap in a separate method and have had better results so obviously what I was doing was causing the weird problem. I just wanted to know why?

Similar Threads

  1. Replies: 3
    Last Post: 27th November 2006, 10:56
  2. QPainter ouside of paintEvent with a pixmap
    By bitChanger in forum Qt Programming
    Replies: 10
    Last Post: 22nd March 2006, 20:45
  3. Replies: 7
    Last Post: 20th March 2006, 21:03
  4. Replies: 12
    Last Post: 5th February 2006, 11:34

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.