Hi,
I need to draw grids in my app. The problem now is performance. The components move jerkily after adding grids. I confirmed from the profiler that scene::drawBackground() was most cpu consuming method.
Can anyone please help me out ? Is there any techinique like caching or something ?
Here is my code
Qt Code:
  1. void SchematicScene::drawBackground(QPainter *p, const QRectF& crect)
  2. {
  3. const QRectF rect = crect.normalized();
  4. p->save();
  5. p->setPen(QPen(Qt::lightGray,1));
  6. int l = int(rect.left());
  7. l -= (l % 10);
  8.  
  9. int r = int(rect.right());
  10. r -= (r % 10);
  11. if(r < int(rect.right()))
  12. r += 10;
  13.  
  14. int t = int(rect.top());
  15. t -= (t % 10);
  16.  
  17. int b = int(rect.bottom());
  18. b -= (b % 10);
  19. if(b < int(rect.bottom()))
  20. b += 10;
  21.  
  22. for( int x = l; x <= r; x+=10)
  23. for( int y = t; y <= b; y+=10)
  24. p->drawPoint(x,y);
  25.  
  26. p->restore();
  27. }
To copy to clipboard, switch view to plain text mode