coordinate system
Use Qpainter to draw with logical coordinates and then convert to the physical coordinates of the drawing device.
The mapping of logical coordinates to physical coordinates is handled by Qpainter's Worldtransform () function, Qpainter's viewport () function, and the window () function.
Worldtransform () function------------------return value for the world transformation matrix
Viewport () function-------------------------return value as viewport rectangle
Window () function--------------------------The return value is a matrix of windows
The viewport (viewport) represents an arbitrary matrix specified under the physical coordinates, and the window (Windows) represents the same matrix under logical coordinates. The coordinates one by one of the four corners of the two matrices correspond, and the Qpainter drawing is plotted under the logical coordinates and corresponds to the physical coordinates.
The use of window-viewport conversions can be a logical coordinate system for application requirements that can be used to separate drawing code from drawing devices.
1 // The following code allows the viewport and window to maintain the same aspect ratio to prevent distortion 2 int side = qmin (width (), height ()); 3 int x = (width ()-side/2); 4 int y = (height ()-side/2); 5 Painter.setviewport (x,y,side,side);
Transformations of four common coordinate systems:
- Pan Qtransform & Translate (qreal dx, qreal dy)
- Rotary Qtransform & Rotate (qreal angle, qt::axis Axis = Qt::zaxis)
- Scaling Qtransform & scale (qreal SX, Qreal Sy)
- Twisted Qtransform & Shear (qreal sh, qreal sv)
Q Save for painter object: Save () saves the current state, and restore () restores the state of the last Save ().
Summary of 2D drawing problems in Qt (II.)----------coordinate system