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