PyQt: viewport vs window - how do you translate co-ordinates?

Veek M vek.m1234 at gmail.com
Sat Sep 23 07:38:45 EDT 2017


pg 329, Rapid GUI Programming
--------------------
http://storage4.static.itmages.com/i/17/0923/h_1506165624_2588733_59fdfcd4cc.png

In PyQt terminology the physical coordinate system is called the “viewport”,
and confusingly, the logical coordinate system is called the “window”.

In Figure 11.4, we have a physical widget size of 800 × 600. By calling setWin-
dow(-60, -60, 120, 120) we can create a “window” with a top-left coordinate of
(-60, -60), a width of 120, a height of 120, and centered at point (0, 0). The
window’s coordinate system is a logical coordinate system that QPainter auto-
matically maps to the underlying physical device. After the setWindow() call,
all our painting takes place using the logical (window) coordinate system.
In this case, the widget is rectangular, but our window has the same width and
height. This means that the items we paint will be stretched out horizontally,
since coordinates in the y-axis will be scaled by QPainter in the ratio 120:600
(1:5), whereas those in the x-axis will be scaled in the ratio 120:800 (1:6 2
3
).

------------------------

1. The physical (coordinate system) widget size is 800x600 = Viewport
2. Logical Coordinates = Window

When he does setWindow(-60, -60, 120, 120) he's moving along a diagonal from top-left to bottom-right. From that point he's then drawing a 120x120 rectangle.

A. So how does he get a (150,200) point and a -37.5 point??? 
B. Also, how is it stretched horizontally? If i use the inner 120x120 as a frame of reference and draw a circle - it'll still be a circle??? Just draw a square on a blackboard.. and then draw a circle in it..

I didn't understand any of that - could someone expand on that para?

C. Why does QPainter have to scale in a different ratio??
QPainter understands two coordinate systems - physical and logical and by default the two systems match each other.

Is there a reading resource that explains the Viewport and translations? I am not a CS student so I did not study computer graphics.


(sorry for using google groups but my knode is broken and pan is horrible on olvwm - my plan is to write myself a News client in PyQt :))



More information about the Python-list mailing list