PDA

View Full Version : Zooming does not work after QTransform



iasuottab
28th November 2011, 03:14
Hi,

I'm trying to implement a function to transform polygons, using QTransform. It works, but it's only transforming around the top-left of the screen, and the polygon does not respond accordingly when I zoom in and zoom out. It just stays at the top left(provided I just draw it at (0,0)), and at that same size, regardless of zooming.

qreal rad = (-angle / 180) * PI;
qreal sina = std::sin(rad);
qreal cosa = std::cos(rad);
QTransform translationTransform(1, 0, 0, 1, point.x(), point.y());
QTransform rotationTransform(cosa, sina, -sina, cosa, 0, 0);
QTransform scalingTransform(1, 0, 0, 1, 0, 0);
QTransform transformMatrix = translationTransform * rotationTransform * scalingTransform;
painter->setWorldTransform(transformMatrix);
painter->drawPath(myPath); //myPath is a QPainterPath of lines



However, if I use QPainter::translate/rotate/scale, it reponds with the zoom, and it is not stuck at the top-left, but it does not draw the polygons as what I wanted.

painter->translate(point);
painter->rotate(-angle);
painter->drawPath(myPath); //myPath is a QPainterPath of lines



I have searched in forums, nothing much on this topic. Read through documents, still do not understand how to solve the problem, but I think it has something to do with the coordinate system (before QTransform, (0,0) is at screen's midpoint; after QTransform, (0,0) is at screen's top-left).

I've been stuck here for more than a week already... Any idea on anything that I missed out?

Thanks in advance.

iasuottab
29th November 2011, 05:20
Hi,

I solved it. For those who have the same problem, i just added a 'true' in a function call...

painter->setWorldTransform(transformMatrix, true);