Mirroring a Pixmap Item around an axis
-
In a game I'm developing I have a Mario class :
class Mario : public QGraphicsPixmapItem
and when right arrow key is pressed I want to change the texture of Mario item from the first picture to the second one below
(every square in the picture is one pixel):In order to achieve this, my idea was to mirror the first texture in the picture above around the green axis . I actually have tried to express this idea in the following code :
if (e->key() == Qt::Key_Right) mario->setPixmap(mario->pixmap().transformed(QTransform().scale(-1, 1)));
but I obtain this situation :
What is a way to achieve a mirroring of the texture around an axis which is not the 'Z' one but the green one you see in the first picture I have posted?
-
Hi,
What do you get if you use the mirrored method ?
-
@SGaist Hi. That method applies to a QImage and in my case I have tried to apply it to the pixmap (returned by pixmap() )of the item but there is such an item because a QImage is a Qpixmape but not viceversa. Am I right?
-
I am not sure I am following you because your transformed call is also applied directly to your QImage.
-
My bad ! I mixed both classes.
What I had in mind was to apply the mirroring or the original QImage and then load it in the item,
-
Well, why not use the setTransform method if your item directly ?
-
No, I suggested to transform the item not it's content hence the link I provided to the QGraphicsItem::setTransform method.
-
@SGaist OK , now I am following you. So according to you in order to mirror mario ,through setTransform method, I should do
something like:mario->setTransform()
and I should chain two consecutive transformations (e.g TRANSLATE + SCALE(-1,1) ) by passing an opportune matrix to the setTransform method. Am I right?
If so, could you show me through a small piece of code how to chain a translation plus a scale operation?
-
Did you already read the Graphics View Overview in Qt's documentation ?