Results 1 to 4 of 4

Thread: PaintEvent Performance

  1. #1
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default PaintEvent Performance

    Hello fellow programmers.

    I have a question regarding my paintEvent in my class which is derived from QWidget. And what I am asking here is why does this paintEvent take up 70-80 % of my cpu when I add this object to a QGraphicsScene and move it around.

    I know I can get a significant boost in performance by setting the QGraphcsItem:eviceCoordinateCache flag as cacheMode but I am just curios why my paintEvent is so heavy on the CPU and if I can somehow improve it.

    PS. The pixmap that I am using is only loading the first time I create the object since I store it in the QPixmapCache and use it from there.

    Qt Code:
    1. void CDITachometer::paintEvent(QPaintEvent *)
    2. {
    3.  
    4. /* Min rotate(-93)
    5.   * Max rotate(162)
    6.   * Mid rotate(36)
    7.   */
    8. QPainter boolPainter(this);
    9. boolPainter.setRenderHint(QPainter::SmoothPixmapTransform);
    10.  
    11. QPixmap pixmap = *QPixmapCache::find(accessibleName());
    12.  
    13. boolPainter.drawPixmap(0, 0, pixmap.scaled(size().width(), size().height(),
    14. Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
    15.  
    16. QTransform transform2;
    17. transform2.translate(size().width()/2, size().height()/2);
    18. transform2.rotate(m_rotation);
    19. transform2.translate(-size().width()/2, -size().height()/2);
    20.  
    21. boolPainter.setTransform(transform2);
    22.  
    23. pixmap = *QPixmapCache::find(accessibleName().append("1"));
    24.  
    25. boolPainter.drawPixmap(0, 0, pixmap.scaled(size().width(), size().height(),
    26. Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
    27. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance and I appritiate all advice and comments

  2. #2
    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: PaintEvent Performance

    It takes lot of time because you are scaling two pixmaps that are probably quite big. You'll get better performance if you prescale them and then insert them into the pixmap cache so that the paint event only extracts the pixmaps and renders them.

    And think if your item really needs to be a QWidget subclass. As I understand it is, currently.
    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. The following user says thank you to wysota for this useful post:

    meazza (27th June 2011)

  4. #3
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PaintEvent Performance

    It takes lot of time because you are scaling two pixmaps that are probably quite big. You'll get better performance if you prescale them and then insert them into the pixmap cache so that the paint event only extracts the pixmaps and renders them.
    Yeah the pixmaps are 500 x 500 which I guess is pretty big. The reason they are scaled is because you can change the size of the widget and the pixmaps are always scaled to the widget size. I did remove the scaling from paintevent now because I dont need to do it if size has not changed, which gave me a bit more performance.

    And think if your item really needs to be a QWidget subclass. As I understand it is, currently.
    Yes it is a subclass of QWidget at the moment. Would I get better performance if I used QGraphicsItem or QGraphicsWidget?

  5. #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: PaintEvent Performance

    Yes, you would get better performance if the item was a graphics item and not a widget.
    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.


Similar Threads

  1. qt paintEvent
    By lzpmail in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2011, 13:13
  2. paintEvent help
    By seltra in forum Newbie
    Replies: 11
    Last Post: 18th September 2010, 19:24
  3. QGraphicsScene in paintEvent ?
    By PLan2010 in forum Newbie
    Replies: 5
    Last Post: 14th June 2010, 12:16
  4. Must QPainter be in paintEvent ??
    By jiapei100 in forum Qt Programming
    Replies: 6
    Last Post: 5th September 2009, 00:09
  5. Replies: 12
    Last Post: 5th February 2006, 10:34

Tags for this Thread

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.