Hi,
I know, that paintEvent() repainted the whole area, even if just one pixel changed.
Now, paintEvent() looks like this:
{
QRect updateRect
= event
->rect
();
updateRect
= QRect(updateRect.
topLeft() / zoom, updateRect.
size() / zoom
);
for(int i = updateRect.left(); i <= updateRect.right(); ++i) {
if(!image.rect().contains(i, 0)) break;
for(int j = updateRect.top(); j <= updateRect.bottom(); ++j) {
if(!image.rect().contains(0, j)) break;
QRect rect
= pixelRect
(i, j
);
if(!event->region().intersect(rect).isEmpty()) {
if(color.alpha() < 255)
painter.fillRect(rect, color);
painter.fillRect(rect, color);
}
}
}
}
void IconEditor::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QRect updateRect = event->rect();
updateRect = QRect(updateRect.topLeft() / zoom, updateRect.size() / zoom);
for(int i = updateRect.left(); i <= updateRect.right(); ++i) {
if(!image.rect().contains(i, 0)) break;
for(int j = updateRect.top(); j <= updateRect.bottom(); ++j) {
if(!image.rect().contains(0, j)) break;
QRect rect = pixelRect(i, j);
if(!event->region().intersect(rect).isEmpty()) {
QColor color = QColor::fromRgba(image.pixel(i, j));
if(color.alpha() < 255)
painter.fillRect(rect, color);
painter.fillRect(rect, color);
}
}
}
}
To copy to clipboard, switch view to plain text mode
So, only the part that changed is repainted. But it's still not possible to paint a continuous line.
Is there a better way to implement paintEvent()?
Bookmarks