Create QTransform given 4 points defining the transformed unit square

Viewed 4038

Given 4 points being be the result of

QPolygon poly = transform.mapToPolygon(QRectF(0, 0, 1, 1));

how can I find QTransform transform? (Even better: also given an arbitrary source rectangle)

Motivation: Given the four corner points of an image to be drawn in a perspectively distorted coordinate system, how can I draw the image using QPainter?

Illustration of the problem

This is a screenshot illustrating the problem in GIMP, where one can transform a layer by moving around the 4 corners of the layer. This results in a perspective transformation. I want to do exactly the same in a Qt application. I know that QTransform is not restricted to affine transformations but can also handle perspective transformations.

2 Answers
Related