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
void SchematicScene
::drawBackground(QPainter *p,
const QRectF
& crect
) {
const QRectF rect
= crect.
normalized();
p->save();
p
->setPen
(QPen(Qt
::lightGray,
1));
int l = int(rect.left());
l -= (l % 10);
int r = int(rect.right());
r -= (r % 10);
if(r < int(rect.right()))
r += 10;
int t = int(rect.top());
t -= (t % 10);
int b = int(rect.bottom());
b -= (b % 10);
if(b < int(rect.bottom()))
b += 10;
for( int x = l; x <= r; x+=10)
for( int y = t; y <= b; y+=10)
p->drawPoint(x,y);
p->restore();
}
void SchematicScene::drawBackground(QPainter *p, const QRectF& crect)
{
const QRectF rect = crect.normalized();
p->save();
p->setPen(QPen(Qt::lightGray,1));
int l = int(rect.left());
l -= (l % 10);
int r = int(rect.right());
r -= (r % 10);
if(r < int(rect.right()))
r += 10;
int t = int(rect.top());
t -= (t % 10);
int b = int(rect.bottom());
b -= (b % 10);
if(b < int(rect.bottom()))
b += 10;
for( int x = l; x <= r; x+=10)
for( int y = t; y <= b; y+=10)
p->drawPoint(x,y);
p->restore();
}
To copy to clipboard, switch view to plain text mode
Bookmarks