PDA

View Full Version : rotating a transformed QGraphicsPixmapItem. not the QPixmap inside



planetLars
15th February 2012, 16:13
Hello,

when I apply a rotation to a QGraphicsPixmapItem after a transform of it, the result is the QPixmap inside the Item gets rotated and then fit to the transform (which operates on the original position) which is a distortion instead of the transformed Item being rotated.

QTransform::quadToQuad(QPolygonF(points),QPolygonF (points2),perspectiveMatrix);
phone->setTransform(perspectiveMatrix);
phone->setRotation(360*angle/6.28);
The perspectiveMatrix creates a trapezoid from a rectangle (so its a perspectived rectangle). This Matrix is dependent on the corners of the rectangle. It establishes a grid in which the original corners are projected to the destination corners. Other grid corners don't form the same shape in a perspective grid. Now the rotation rotates the original Pixmap away from the original corners and then the Pixmap is projected to some perspectived grid corners which are different than the destination corners as the original corners area different now thus the result is a deformed trapezoid.

I like to have the transformed Item as a whole being rotated just like when you move and rotate a cut photograph on a desk it doesn't get distorted to having cuts at new positions inside the photo because there was the place of the cut on the desk but the photo remains intact when moving from A to B.

I can understand what can cause this from a implementation standpoint but this is counterintuitive imo. Unfortunately Qt operates on the View or Scene layer as documented by the setTransformOriginPoint being in Scene/View coordinates rather than Item coordinates when wanting to set that point for the Item thus one always has to know every translation etc. rather than the Item carrying the point with it.

If there is a way in Qt to achieve what I want, I'm going to be very joyful to read! (any hints and comments also welcome!)

Added after 40 minutes:

I found a solution:

I can do the perspective transformation on the Pixmap itself and leave the rotation as the only transformation in the Item:

phone->setPixmap((sms->pixmap()).transformed(perspectiveMatrix,Qt::Smooth Transformation).scaledToWidth(newwidth),Qt::Smooth Transformation));

Before, all transformations were applied to the Item coordinates. A functionality to rotate an Item inside a Scene just as the Origin is in scene coordinates would be helpful.

If Qt has another solution I'm still glad to hear.

My solution corrects for the in-pixmap transformation letting the pixmaps size remain untouched. As my perspectived rectangle is going to be wider I set the width accordingly.