Coordinate System
The coordinate system is controlled by the QPainter class. Together with the QPaintDevice and QPaintEngine classes, QPainter form the basis of Qt's painting system, Arthur. QPainter is used to perform drawing operations, QPaintDevice is an abstraction of a two-dimensional space that can be painted on using a QPainter, and QPaintEngine provides the interface that the painter uses to draw onto different types of devices.
坐标系统受QPainter类所控制。和QPaintDevice、QPaintEngine类组成了Qt的绘制系统Arthur。QPainter被用来执行绘制操作,QPaintDevice是二维空间的抽象,能够使用QPainter来绘制,QPaintEngine提供了一些接口,让QPainter能够在不同类型的设备上进行绘制。
Rendering
Logical Representation
The size (width and height) of a graphics primitive always correspond to its mathematical model, ignoring the width of the pen it is rendered with:
图元的尺寸总是对应于它的数学模型,忽略了渲染它的笔的宽度:
QRect(QPoint(1, 2), QPoint(7, 6))
QRect(QPoint(1, 2), QSize(6, 4))
QRect(1, 2, 6, 4)
QLine(QPoint(2, 7), QPoint(6, 1))
QLine(2, 7, 6, 1)
Aliased Painting 锯齿绘制
When drawing, the pixel rendering is controlled by the QPainter::Antialiasing render hint.
在绘制时,像素的渲染可以通过QPainter::Antialiasing的渲染提示来控制的。
The RenderHint enum is used to specify flags to QPainter that may or may not be respected by any given engine. The QPainter::Antialiasing value indicates that the engine should antialias edges of primitives if possible, i.e. smoothing the edges by using different color intensities.
渲染提示枚举用来指定QPainter的标志,可能不会被给定的引擎遵循。QPainter::Antialiasing指明了应当尽可能的对图元的边缘进行抗锯齿化。例如,使用不同的颜色强度平滑边缘。
But by default the painter is aliased and other rules apply: When rendering with a one pixel wide pen the pixels will be rendered to the right and below the mathematically defined points. For example:
但是默认的painter是锯齿化的,其他规则也适用:当使用一个像素宽的笔,像素点将会被渲染到几何定义点的右边或者下边。
QPainter painter(this);
painter.setPen(Qt::darkGreen);
// Using the (x y w h) overload
painter.drawRect(1, 2, 6, 4);
QPainter painter(this);
painter.setPen(Qt::darkGreen);
painter.drawLine(2, 7, 6, 1);