Results 1 to 2 of 2

Thread: Faster paintEvent

  1. #1
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Angry Faster paintEvent

    The paintevent that sets background bitmap and draws the needle takes ~220 ms to execute on my laptop.

    How I can I optimize the paintevent and make it faster to execute?

    Qt Code:
    1. QPixmap Meter::setBitmap()
    2. {
    3.  
    4. QPixmap* pixmap;
    5.  
    6. if(mReset)
    7. {
    8.  
    9. mReset = false;
    10. pixmap = & pixmap1;
    11.  
    12. }
    13. else
    14. {
    15.  
    16. if(mStatus == true)
    17. {
    18.  
    19. pixmap = & pixmap2;
    20.  
    21. }
    22. else if(mStatus == false )
    23. {
    24.  
    25. if( mFinalTorque <= mTorque)
    26. {
    27.  
    28. pixmap = & pixmap3;
    29.  
    30. }
    31. else
    32. {
    33.  
    34. pixmap = & pixmap4;
    35.  
    36. }
    37.  
    38. }
    39.  
    40. }
    41.  
    42. return *pixmap;
    43.  
    44. }
    45.  
    46. void Meter::paintEvent(QPaintEvent* pe)
    47. {
    48. struct timeval tv1,tv2;
    49.  
    50. gettimeofday(&tv1, NULL);
    51.  
    52. myPaintEvent(pe);
    53.  
    54. gettimeofday(&tv2, NULL);
    55.  
    56. qDebug() << "Meter::paintEvent: " << (tv2.tv_sec-tv1.tv_sec)*1000000+(tv2.tv_usec-tv1.tv_usec) << "us";
    57. }
    58.  
    59. void Meter::myPaintEvent(QPaintEvent*)
    60. {
    61.  
    62. QPainter paintNeedle(this);
    63. QColor needleColor(255, 230, 0);
    64.  
    65. paintNeedle.setBackgroundMode (Qt::TransparentMode);
    66. paintNeedle.drawPixmap(mPixmapXCoord, mPixmapYCoord, setBitmap());
    67.  
    68. paintNeedle.translate(mVectorTranslationX, mVectorTranslationY);
    69.  
    70. paintNeedle.setPen(Qt::NoPen);
    71. paintNeedle.setBrush(needleColor);
    72.  
    73. paintNeedle.save();
    74. paintNeedle.rotate(mFinalPoint);
    75. paintNeedle.drawConvexPolygon(needle, 3);
    76. paintNeedle.restore();
    77.  
    78. paintNeedle.setPen(needleColor);
    79.  
    80. QRect rect(mEllipseX, mEllipseY, mEllipseWidht, mEllipseHeight);
    81. paintNeedle.drawEllipse(rect);
    82.  
    83. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Faster paintEvent

    Of course the paintEvent does not take 220ms? My mistake, on my embedded arm the paintevent takes ~7ms.

    Its a kind of speedometer that is painted...The background makes up of four bitmaps because the meter can be in four different states.

    Qt Code:
    1. paintNeedle.drawPixmap(mPixmapXCoord, mPixmapYCoord, setBitmap());
    To copy to clipboard, switch view to plain text mode 

    ...takes ~5ms and the rendering of the needle below takes about ~2ms.

    I wonder if it is more effective to render the background states instead?

Similar Threads

  1. Possible to use a widget in another widget's paintEvent?
    By robot_love in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2008, 06:18
  2. painting a widget outside a paintEvent
    By jayw710 in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2007, 00:18
  3. What's faster: QPixmap-to-QImage or QImage-to-QPixmap
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2006, 18:11
  4. Replies: 3
    Last Post: 27th November 2006, 10:56
  5. faster QScrollView
    By firas in forum Qt Programming
    Replies: 2
    Last Post: 29th April 2006, 19:49

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.