# Perspective view in Qt.

• Hi Guys,

It has been roughly a month I have started working with Qt. Right now I am trying to vie an image in perspective view. Lets say I want to rotate the image in along the Y axis, I am using the Qtransform function to rotate.. here is the code snippet.
int angle=20;
QTransform transform;
transform.rotate(angle, Qt::YAxis);
image = QImage(”:/images/livingroom.jpg”);
image = image.scaledToWidth(this->width());
image = image.transformed(transform);

But this is not producing the desired results. The result image is not a perspective view. Can anybody please help me in achieving this?

• I believe you are looking for

or,

depending on the original image.

• Hi,

Pardon my ignorance, but do i need to find out the second polygon,( the one for the perspective view) manually? After that I have to map the image to the new polygon? Please correct me if I am wrong..

• Nope, that sounds about right. I don't suspect it should be too dificult.
ie. To make the image "fade" to the right.
Copy the original polygon,
in the new copy divide imageheight by 2, adjust the upper right y value to imageheight/4 and lower right y value = imageheight *3/4.

• I found this example using matrix. This is another way to go.

• Lets say I want to rotate it by 25 degrees along the y axis, so how do i calculate the height of the right edge of the polygon?

Because here you are saying the right edge is half of the left edge..but how do u find out this relation

• yes Even I had stumbled across that example, but i cannot find the code to do that....I can see that the snapshots given are exactly what i want

• I think I'm getting a bit confused about what you are trying to do here. I'm starting to suspect that you are trying to do a 3d flyby of "livingroom.jpg"?
If this is the case, assume you are at 89.5 degrees. You will be looking more or less at the edge of a pic, a vertical line. If this is the case it's time to start thinking about Qt OpenGL classes and go 3D.

• Umm,,,I would say I am trying to achieve exactly the same thing that the snapshots in the example show...
https://blog.qt.digia.com/blog/2006/09/21/perspective-transformations/