I figured it out and here's the answer, If someone googled it:
I made this code to see the difference and how both work, I'm outputting the window
and viewport
coordinates while resizing the window.
(just used arbitrary numbers)
QPen pen(Qt::blue,3,Qt::SolidLine);
painter.setPen(pen);
painter.setViewport(50,50,100,100);
painter.setWindow(-100,-150,200,200);
QRect rect= painter.viewport();
QRect wind= painter.window();
cout<< rect.x() << " "<< rect.y() << " "<< rect.height() << " "<< rect.width() <<endl;
cout<< wind.x() << " "<< wind.y() << " "<< wind.height() << " "<< wind.width() <<endl;
painter.drawRect(0,0,200,202);
and ran the program with either line of those two commented
painter.setViewport(50,50,100,100);
painter.setWindow(-100,-150,200,200);
While commenting setwindow
, and setting setviewport
, the rectangle should get smaller,why?
On resizing the window, the logical(window) and the physical(viewport) coordinates should both change the same.But here I set
Viewport
constant, so the logical coordinates(the drawing one) is only one changes. So while the window resize larger the logical coordinates has to fit into the small constant viewport
and consequently the rectangle get smaller