Reputation: 2118
I have a problem with clipping in Qt. I have a widget in which I paint a big array of rectangles. As I only change a few rectangles from time-to-time, I want to paint only a little part of the widget (only these rectangles) and clip the paint area to these parts.
The isNew()
function is true if the rectangle receives new color since the previous painting.
void Environment::paintEvent(QPaintEvent *event)
{
QPainter painter (this);
Tile t;
//paint the matrix
for(int i=0; i<size; ++
t = matrix[i+j*yizeY];
if(t.isNew()){
painter.setClipRegion(QRegion(t.getRect()));
painter.setBrush(t.getColor());
painter.drawRect(t.getRect());
t.used();
}
}
}
What am I doing wrong? My program is running even slower when I use the setClipRegion(...)
function.
Upvotes: 0
Views: 1593
Reputation: 1180
If you want to improve performance, you can paint all those rectangles on a QPixmap. As you can draw to the pixmap anytime, you can draw the tiles directly to the pixmap when they needs an update. On the paint event you just draw the "already-rendered" pixmap.
That way you don't have to remember which tiles changed, and you can avoid looping through the whole matrix.
Upvotes: 1