Problem using drawPixmap() to do scrolling effect in QPixmap
I'm trying to create a scrolling effect for painting done in a QPixmap, using a function that takes a pixmap and paints it into itself with the required deltas:
Code:
void scrollGraphics
(int dx,
int dy,
QPixmap *thePixmap
) {
p.begin(thePixmap);
p.drawPixmap(dx, dy, *thePixmap);
p.end();
}
If dx and/or dy < 0, the graphics of thePixmap appear shifted by the correct amount. However, if I pass a value greater than 0 for dx and/or dy, drawPixmap() paints into thePixmap multiple shifted copies of itself.
Is this a Qt bug? Or am I missing something?
Re: Problem using drawPixmap() to do scrolling effect in QPixmap
You're missing a fact that you are trying to overdraw something with something that is currently being overdrawn... Paint a picture, let it dry and try painting this picture again shifted 1/3 to the right only by looking at the picture. You'll soon reach a stage when what you should paint now has just been overpainted with what is 1/3 of the image to the left. I assume that's exactly what you're observing. And I'm assuming you're doing that on Windows as on Unix you'd probably just get garbage.
Anyway... remove the pointers, work on copies - QPixmap is shared anyway.
Re: Problem using drawPixmap() to do scrolling effect in QPixmap
Dziękuję serdecznie. :) I now understand why I can't paint a pixmap directly into itself.
However, I'm not completely clear on what you mean here:
Quote:
Originally Posted by
wysota
remove the pointers, work on copies - QPixmap is shared anyway.
I understand that I need to make a copy of the pixmap, then paint the copy back into the original. But why are pointers bad in this case, and what do you mean by shared?
Thanks.
Re: Problem using drawPixmap() to do scrolling effect in QPixmap
Quote:
Originally Posted by
ajoffe
Dziękuję serdecznie. :)
Proszę uprzejmie.
Quote:
I understand that I need to make a copy of the pixmap, then paint the copy back into the original. But why are pointers bad in this case, and what do you mean by shared
Try something like this:
Code:
{
result.fill(Qt::transparent); // optionally
p.drawPixmap(dx, dy, thePixmap);
p.end();
return result;
}
And read about "implicit sharing".
Re: Problem using drawPixmap() to do scrolling effect in QPixmap
Quote:
Originally Posted by
wysota
Proszę uprzejmie.
hmmmm... :)
Re: Problem using drawPixmap() to do scrolling effect in QPixmap
Quote:
Originally Posted by
MrDeath
hmmmm... :)
It means "you're welcome" in Polish. It's not a multi-post foreign language conversation :)
Re: Problem using drawPixmap() to do scrolling effect in QPixmap
Quote:
Originally Posted by
wysota
It means "you're welcome" in Polish. It's not a multi-post foreign language conversation :)
did i complaint? :). Anyways i learned one sentence in polish though:)