Summary of 2D drawing problems in Qt (II.)----------coordinate system

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.