PDA

View Full Version : Problem using drawPixmap() to do scrolling effect in QPixmap



ajoffe
7th July 2009, 22:37
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:


void scrollGraphics(int dx, int dy, QPixmap *thePixmap)
{
QPainter p;
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?

wysota
7th July 2009, 23:04
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.

ajoffe
8th July 2009, 20:03
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:


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.

wysota
8th July 2009, 21:21
Dziękuję serdecznie. :)
Proszę uprzejmie.


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:


QPixmap scrollGraphics(int dx, int dy, const QPixmap &thePixmap)
{
QPixmap result(thePixmap.size());
result.fill(Qt::transparent); // optionally
QPainter p(&result);
p.drawPixmap(dx, dy, thePixmap);
p.end();
return result;
}

And read about "implicit sharing".

nish
9th July 2009, 01:50
Proszę uprzejmie.


hmmmm... :)

wysota
9th July 2009, 08:09
hmmmm... :)

It means "you're welcome" in Polish. It's not a multi-post foreign language conversation :)

nish
9th July 2009, 08:11
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:)