QTransform Class Reference

[QtGui module]

该QTransform类指定坐标系的2D变换。More…

Types

  • enum TransformationType { TxNone, TxTranslate, TxScale, TxRotate, TxShear, TxProject }

Methods

  • __init__ (self)
  • __init__ (self, float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33 = 1)
  • __init__ (self, float h11, float h12, float h13, float h21, float h22, float h23)
  • __init__ (self, QMatrix mtx)
  • __init__ (self, QTransform)
  • QTransform adjoint (self)
  • float det (self)
  • float determinant (self)
  • float dx (self)
  • float dy (self)
  • (QTransform, bool invertible) inverted (self)
  • bool isAffine (self)
  • bool isIdentity (self)
  • bool isInvertible (self)
  • bool isRotating (self)
  • bool isScaling (self)
  • bool isTranslating (self)
  • float m11 (self)
  • float m12 (self)
  • float m13 (self)
  • float m21 (self)
  • float m22 (self)
  • float m23 (self)
  • float m31 (self)
  • float m32 (self)
  • float m33 (self)
  • (int tx, int ty) map (self, int x, int y)
  • (float tx, float ty) map (self, float x, float y)
  • QPoint map (self, QPoint p)
  • QPointF map (self, QPointF p)
  • QLine map (self, QLine l)
  • QLineF map (self, QLineF l)
  • QPolygonF map (self, QPolygonF a)
  • QPolygon map (self, QPolygon a)
  • QRegion map (self, QRegion r)
  • QPainterPath map (self, QPainterPath p)
  • QRect mapRect (self, QRect)
  • QRectF mapRect (self, QRectF)
  • QPolygon mapToPolygon (self, QRect r)
  • reset (self)
  • QTransform rotate (self, float angle, Qt.Axis axis = Qt.ZAxis)
  • QTransform rotateRadians (self, float angle, Qt.Axis axis = Qt.ZAxis)
  • QTransform scale (self, float sx, float sy)
  • setMatrix (self, float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33)
  • QTransform shear (self, float sh, float sv)
  • QMatrix toAffine (self)
  • QTransform translate (self, float dx, float dy)
  • QTransform transposed (self)
  • TransformationType type (self)

Static Methods

  • QTransform fromScale (float dx, float dy)
  • QTransform fromTranslate (float dx, float dy)
  • bool quadToQuad (QPolygonF one, QPolygonF two, QTransform result)
  • bool quadToSquare (QPolygonF quad, QTransform result)
  • bool squareToQuad (QPolygonF square, QTransform result)

Special Methods

  • QTransform __add__ (self, float n)
  • QTransform __div__ (self, float n)
  • bool __eq__ (self, QTransform)
  • QTransform __iadd__ (self, float num)
  • QTransform __idiv__ (self, float div)
  • QTransform __imul__ (self, QTransform)
  • QTransform __imul__ (self, float num)
  • QTransform __isub__ (self, float num)
  • QTransform __mul__ (self, QTransform o)
  • QTransform __mul__ (self, float n)
  • bool __ne__ (self, QTransform)
  • QTransform __sub__ (self, float n)

Detailed Description

这个类可以醃制。

该QTransform类指定坐标系的2D变换。

一个转换指定如何翻译,缩放,剪切,旋转或投影坐标系,并绘制图形时,通常会使用。

QTransform不同于QMatrix(obsolete)中,这是一个真正的3×3矩阵,使透视变换。 QTransform的toAffine( )方法允许铸造QTransform到QMatrix(obsolete)。如果一个透视变换已被指定的矩阵,则转换将导致数据丢失。

QTransform是Qt推荐的转换类。

一个QTransform对象可使用内置的setMatrix( )scale( )rotate( )translate()和shear()函数。另外,它可以通过施加建basic matrix operations。该矩阵也可以被定义时构造,并且它可以使用被重置为单位矩阵(默认值)的reset()函数。

该QTransform类支持的图形原语映射:一个给定的点,线,多边形,区域或画家路径可以映射到由坐标系定义this使用矩阵map()函数。在情况下的四边形的,它的坐标可以用转化的mapRect()函数。矩形也可以被改造成一个polygon(映射到定义的坐标系this矩阵),使用mapToPolygon()函数。

QTransform提供isIdentity()函数,如果矩阵是单位矩阵,并且该方法返回True,则isInvertible( )函数如果矩阵是非奇异的(即AB = BA = I ),它返回True 。该inverted( )函数返回一个倒置的副本this矩阵,如果它是可逆的(否则返回单位矩阵) ,以及adjoint( )返回矩阵的标准伴随。此外, QTransform提供determinant( )函数返回矩阵的行列式。

最后, QTransform类支持矩阵乘法,加法和减法,以及类的对象可以被串流播放,以及比较。

Rendering Graphics

在绘制图形时,矩阵定义转换,但实际转换是由绘图函数中执行QPainter

默认情况下,QPainter操作相关联的设备自己的坐标系上。标准坐标系统QPaintDevice有其原点位于左上角的位置。该x值向右增大;y值向下增大。有关完整说明,请参阅coordinate system文档。

QPainter有功能,平移,缩放,剪切和旋转坐标系统,而无需使用QTransform 。例如:

| QTransform Class Reference - 图1 |

  1. void SimpleTransformation.paintEvent([QPaintEvent](qpaintevent.html) *)
  2. {
  3. [QPainter]($docs-qpainter.html) painter(this);
  4. painter.setPen([QPen](qpen.html)([Qt](qt.html).blue, 1, [Qt](qt.html).DashLine));
  5. painter.drawRect(0, 0, 100, 100);
  6. painter.rotate(45);
  7. painter.setFont([QFont](qfont.html)("Helvetica", 24));
  8. painter.setPen([QPen](qpen.html)([Qt](qt.html).black, 1));
  9. painter.drawText(20, 10, "QTransform");
  10. }

|

虽然这些功能都非常的方便,它可以更有效地建立一个QTransform和呼叫QPainter.setTransform( )如果你想执行一个以上的变换操作。例如:

| QTransform Class Reference - 图2 |

  1. void CombinedTransformation.paintEvent([QPaintEvent](qpaintevent.html) *)
  2. {
  3. [QPainter]($docs-qpainter.html) painter(this);
  4. painter.setPen([QPen](qpen.html)([Qt](qt.html).blue, 1, [Qt](qt.html).DashLine));
  5. painter.drawRect(0, 0, 100, 100);
  6. QTransform transform;
  7. transform.translate(50, 50);
  8. transform.rotate(45);
  9. transform.scale(0.5, 1.0);
  10. painter.setTransform(transform);
  11. painter.setFont([QFont](qfont.html)("Helvetica", 24));
  12. painter.setPen([QPen](qpen.html)([Qt](qt.html).black, 1));
  13. painter.drawText(20, 10, "QTransform");
  14. }

|

Basic Matrix Operations

QTransform Class Reference - 图3

一个QTransform对象包含一个3× 3的矩阵。该m31dx)和m32dy)元素指定水平和垂直平移。该m11m22元素指定水平和垂直缩放。该m21m12元素指定水平和垂直shearing。最后,本m13m23元素指定水平和垂直投影,与m33作为一个额外的投影系数。

使用下列公式QTransform转换成在平面上的点到另一点:

  1. x' = m11*x + m21*y + dx
  2. y' = m22*y + m12*x + dy
  3. if (is not affine) {
  4. w' = m13*x + m23*y + m33
  5. x' /= w'
  6. y' /= w'
  7. }

The point (x, y) is the original point, and (x’, y’) is the transformed point. (x’, y’) can be transformed back to (x, y) by performing the same operation on the inverted() matrix.

The various matrix elements can be set when constructing the matrix, or by using the setMatrix() function later on. They can also be manipulated using the translate(), rotate(), scale() and shear() convenience functions. The currently set values can be retrieved using the m11(), m12(), m13(), m21(), m22(), m23(), m31(), m32(), m33(), dx() and dy() functions.

Translation is the simplest transformation. Setting dx and dy will move the coordinate system dx units along the X axis and dy units along the Y axis. Scaling can be done by setting m11 and m22. For example, setting m11 to 2 and m22 to 1.5 will double the height and increase the width by 50%. The identity matrix has m11, m22, and m33 set to 1 (all others are set to 0) mapping a point to itself. Shearing is controlled by m12 and m21. Setting these elements to values different from zero will twist the coordinate system. Rotation is achieved by setting both the shearing factors and the scaling factors. Perspective transformation is achieved by setting both the projection factors and the scaling factors.

Here’s the combined transformations example using basic matrix operations:

| QTransform Class Reference - 图4 |

  1. void BasicOperations.paintEvent([QPaintEvent](qpaintevent.html) *)
  2. {
  3. double pi = 3.14;
  4. double a = pi/180 * 45.0;
  5. double sina = sin(a);
  6. double cosa = cos(a);
  7. QTransform translationTransform(1, 0, 0, 1, 50.0, 50.0);
  8. QTransform rotationTransform(cosa, sina, -sina, cosa, 0, 0);
  9. QTransform scalingTransform(0.5, 0, 0, 1.0, 0, 0);
  10. QTransform transform;
  11. transform = scalingTransform * rotationTransform * translationTransform;
  12. [QPainter]($docs-qpainter.html) painter(this);
  13. painter.setPen([QPen](qpen.html)([Qt](qt.html).blue, 1, [Qt](qt.html).DashLine));
  14. painter.drawRect(0, 0, 100, 100);
  15. painter.setTransform(transform);
  16. painter.setFont([QFont](qfont.html)("Helvetica", 24));
  17. painter.setPen([QPen](qpen.html)([Qt](qt.html).black, 1));
  18. painter.drawText(20, 10, "QTransform");
  19. }

|


Type Documentation

  1. QTransform.TransformationType
Constant Value
QTransform.TxNone 0x00
QTransform.TxTranslate 0x01
QTransform.TxScale 0x02
QTransform.TxRotate 0x04
QTransform.TxShear 0x08
QTransform.TxProject 0x10

Method Documentation

  1. QTransform.__init__ (self)

构造一个单位矩阵。

所有的元素都设置为零,除了m11m22(指定刻度)和m13它被设置为1 。

See also reset( ) 。

  1. QTransform.__init__ (self, float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33 = 1)
  1. QTransform.__init__ (self, float h11, float h12, float h13, float h21, float h22, float h23)

构造一个矩阵的元素,m11m12m13m21m22m23m31m32m33

See also setMatrix( ) 。

  1. QTransform.__init__ (self, QMatrix mtx)

构造一个矩阵的元素,m11m12m21m22dxdy

See also setMatrix( ) 。

  1. QTransform.__init__ (self, QTransform)

构造一个矩阵,是给定一个副本matrix。注意,这个m13m23m33元件分别设置为0,0和1。

  1. QTransform QTransform.adjoint (self)

[

返回该矩阵的伴随。

  1. float QTransform.det (self)
  1. float QTransform.determinant (self)

返回矩阵的行列式。

  1. float QTransform.dx (self)

返回水平平移因子。

]($docs-qtransform.html)

See also m31( )translate()和Basic Matrix Operations

  1. float QTransform.dy (self)

返回垂直平移因子。

See also translate()和Basic Matrix Operations

  1. QTransform QTransform.fromScale (float dx, float dy)

创建其对应于缩放的矩阵sx水平和sy垂直。这是相同的QTransform( ) 。规模( SX , SY ),但稍快。

此功能被引入Qt的4.5 。

  1. QTransform QTransform.fromTranslate (float dx, float dy)

创建其对应于翻译成矩阵dx沿x轴和dy沿y轴。这是相同的QTransform( ) ,翻译( DX,DY ),但稍快。

此功能被引入Qt的4.5 。

  1. (QTransform, bool invertible) QTransform.inverted (self)

返回该矩阵的一个倒置的副本。

如果矩阵是奇异的(不可逆的) ,则返回的矩阵是单位矩阵。如果invertible是有效的(即不为0 ) ,将其值设置为True,如果矩阵是可逆的,否则设置为False 。

See also isInvertible( ) 。

  1. bool QTransform.isAffine (self)

返回True如果矩阵表示仿射变换,否则返回False 。

  1. bool QTransform.isIdentity (self)

返回True如果矩阵为单位矩阵,否则返回False 。

See also reset( ) 。

  1. bool QTransform.isInvertible (self)

返回True如果矩阵是可逆的,否则返回False 。

See also inverted( ) 。

  1. bool QTransform.isRotating (self)

返回True如果矩阵代表某种旋转变换,否则返回False 。

See also reset( ) 。

  1. bool QTransform.isScaling (self)

返回True如果矩阵表示缩放转换,否则返回False 。

See also reset( ) 。

  1. bool QTransform.isTranslating (self)

返回True如果矩阵表示平移变换,否则返回False 。

See also reset( ) 。

  1. float QTransform.m11 (self)

返回水平缩放系数。

See also scale()和Basic Matrix Operations

  1. float QTransform.m12 (self)

返回垂直剪切因素。

See also shear()和Basic Matrix Operations

  1. float QTransform.m13 (self)

返回水平投影的因素。

See also translate()和Basic Matrix Operations

  1. float QTransform.m21 (self)

返回水平剪切的因素。

See also shear()和Basic Matrix Operations

  1. float QTransform.m22 (self)

返回垂直缩放系数。

See also scale()和Basic Matrix Operations

  1. float QTransform.m23 (self)

返回垂直投影的因素。

See also translate()和Basic Matrix Operations

  1. float QTransform.m31 (self)

返回水平平移因子。

See also dx( )translate()和Basic Matrix Operations

  1. float QTransform.m32 (self)

返回垂直平移因子。

See also dy( )translate()和Basic Matrix Operations

  1. float QTransform.m33 (self)

返回的分频因子。

See also translate()和Basic Matrix Operations

  1. (int tx, int ty) QTransform.map (self, int x, int y)

对应给定的坐标xy成由该矩阵定义的坐标系。被放置在所得到的值txty元。

则坐标值用下面的公式转化:

  1. x' = m11*x + m21*y + dx
  2. y' = m22*y + m12*x + dy
  3. if (is not affine) {
  4. w' = m13*x + m23*y + m33
  5. x' /= w'
  6. y' /= w'
  7. }

点(x ,y)是原始的点,和( X’,Y ‘)是变换后的​​点。

See also Basic Matrix Operations

  1. (float tx, float ty) QTransform.map (self, float x, float y)

这是一个重载函数。

创建并返回一个QPointF对象,它是给定的点的副本,p,映射到由该矩阵定义的坐标系。

  1. QPoint QTransform.map (self, QPoint p)

[

这是一个重载函数。

]($docs-qpoint.html)

创建并返回一个QPoint对象,它是给定一个副本point,映射到由该矩阵定义的坐标系。需要注意的是转换后的坐标四舍五入到最接近的整数。

  1. QPointF QTransform.map (self, QPointF p)

[

这是一个重载函数。

]($docs-qpointf.html)

创建并返回一个QLineF对象,它是给定行的一个副本,l,映射到由该矩阵定义的坐标系。

  1. QLine QTransform.map (self, QLine l)

[

这是一个重载函数。

]($docs-qline.html)

创建并返回一个QLine对象,它是给定一个副本line,映射到由该矩阵定义的坐标系。需要注意的是转换后的坐标四舍五入到最接近的整数。

  1. QLineF QTransform.map (self, QLineF l)

[

这是一个重载函数。

]($docs-qlinef.html)

创建并返回一个QPolygonF对象,它是给定一个副本polygon,映射到由该矩阵定义的坐标系。

  1. QPolygonF QTransform.map (self, QPolygonF a)

[

这是一个重载函数。

]($docs-qpolygonf.html)

创建并返回一个QPolygon对象,它是给定一个副本polygon,映射到由该矩阵定义的坐标系。需要注意的是转换后的坐标四舍五入到最接近的整数。

  1. QPolygon QTransform.map (self, QPolygon a)

[

这是一个重载函数。

]($docs-qpolygon.html)

创建并返回一个QRegion对象,它是给定一个副本region,映射到由该矩阵定义的坐标系。

调用此方法可以是相当昂贵的,如果旋转或剪切的使用。

  1. QRegion QTransform.map (self, QRegion r)

[

这是一个重载函数。

]($docs-qregion.html)

创建并返回一个QPainterPath对象,它是给定一个副本path,映射到由该矩阵定义的坐标系。

  1. QPainterPath QTransform.map (self, QPainterPath p)

[

这是一个重载函数。

对应给定的坐标xy成由该矩阵定义的坐标系。被放置在所得到的值txty元。需要注意的是转换后的坐标四舍五入到最接近的整数。

]($docs-qpainterpath.html)

  1. QRect QTransform.mapRect (self, QRect)

创建并返回一个QRectF对象,它是给定一个副本rectangle,映射到由该矩阵定义的坐标系。

矩形的坐标是用下面的公式转化:

  1. x' = m11*x + m21*y + dx
  2. y' = m22*y + m12*x + dy
  3. if (is not affine) {
  4. w' = m13*x + m23*y + m33
  5. x' /= w'
  6. y' /= w'
  7. }

If rotation or shearing has been specified, this function returns the bounding rectangle. To retrieve the exact region the given rectangle maps to, use the mapToPolygon() function instead.

See also mapToPolygon() and Basic Matrix Operations.

  1. QRectF QTransform.mapRect (self, QRectF)

  1. QPolygon QTransform.mapToPolygon (self, QRect r)

创建并返回一个QPolygon给定的表示rectangle,映射到由该矩阵定义的坐标系。

矩形的坐标是用下面的公式转化:

  1. x' = m11*x + m21*y + dx
  2. y' = m22*y + m12*x + dy
  3. if (is not affine) {
  4. w' = m13*x + m23*y + m33
  5. x' /= w'
  6. y' /= w'
  7. }

多边形和矩形的行为略有不同,当转换(由于四舍五入的整数) ,所以matrix.map(QPolygon(rectangle))并不总是相同matrix.mapToPolygon(rectangle)

See also mapRect()和Basic Matrix Operations

  1. bool QTransform.quadToQuad (QPolygonF one, QPolygonF two, QTransform result)

创建一个变换矩阵,trans,映射一个四边形,one到另一个四边多边形,two。返回True如果转换是可能的;否则返回False。

这是一个方便的方法相结合quadToSquare()和squareToQuad()方法。它允许输入四要转变成任何其他四。

See also squareToQuad()和quadToSquare( ) 。

  1. bool QTransform.quadToSquare (QPolygonF quad, QTransform result)

创建一个变换矩阵,trans,映射一个四边形,quad,到单位正方形。返回True如果变换构造还是假,如果这样的转变并不存在。

See also squareToQuad()和quadToQuad( ) 。

  1. QTransform.reset (self)

重置矩阵单位矩阵,即所有元素都设置为零,除非m11m22(指定刻度)和m33它被设置为1 。

See also QTransform( )isIdentity()和Basic Matrix Operations

  1. QTransform QTransform.rotate (self, float angle, Qt.Axis axis = Qt.ZAxis)

[

由给定的逆时针旋转的坐标系angle关于指定axis并返回一个引用到矩阵。

]($docs-qtransform.html)

请注意,如果你申请一个QTransform在小窗口坐标定义的一个点,该旋转方向将因为y轴指向下是顺时针。

的角度被指定为度。

See also setMatrix( ) 。

  1. QTransform QTransform.rotateRadians (self, float angle, Qt.Axis axis = Qt.ZAxis)

[

由给定的逆时针旋转的坐标系angle关于指定axis并返回一个引用到矩阵。

]($docs-qtransform.html)

请注意,如果你申请一个QTransform在小窗口坐标定义的一个点,该旋转方向将因为y轴指向下是顺时针。

的角度被指定为弧度。

See also setMatrix( ) 。

  1. QTransform QTransform.scale (self, float sx, float sy)

[

通过缩放坐标系sx水平和sy垂直,并返回一个引用到矩阵。

]($docs-qtransform.html)

See also setMatrix( ) 。

  1. QTransform.setMatrix (self, float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33)

设置矩阵的元素为指定的值,m11m12m13 m21m22m23 m31m32m33。请注意,此功能取代了以前的值。QTransform提供translate( )rotate( )scale()和shear( )方便的功能来操作基于当前定义的坐标系统中的各种矩阵元素。

See also QTransform( ) 。

  1. QTransform QTransform.shear (self, float sh, float sv)

[

通过剪坐标系sh水平和sv垂直,并返回一个引用到矩阵。

]($docs-qtransform.html)

See also setMatrix( ) 。

  1. bool QTransform.squareToQuad (QPolygonF square, QTransform result)

创建一个变换矩阵,trans,映射一个单位正方形四边多边形,quad。返回True如果变换构造还是假,如果这样的转变并不存在。

See also quadToSquare()和quadToQuad( ) 。

  1. QMatrix QTransform.toAffine (self)

返回QTransform作为仿射矩阵。

Warning:如果已指定一个透视变换,那么转换将导致数据丢失。

  1. QTransform QTransform.translate (self, float dx, float dy)

[

移动的坐标系统dx沿x轴和dy沿着y轴,并返回引用到矩阵。

]($docs-qtransform.html)

See also setMatrix( ) 。

  1. QTransform QTransform.transposed (self)

[

返回该矩阵的转置。

]($docs-qtransform.html)

  1. TransformationType QTransform.type (self)

[

返回这个矩阵的转换类型。

改造型是最高的枚举值捕获所有矩阵的变换。例如,如果两个矩阵规模和剪刀,类型是TxShear,因为TxShear具有比更高的枚举值TxScale

了解矩阵的变换类型是优化有用:你经常可以更优化处理特定类型的处理比一般情况下。

]($docs-qtransform.html#TransformationType-enum)

  1. QTransform QTransform.__add__ (self, float n)

  1. QTransform QTransform.__div__ (self, float n)

[

  1. bool QTransform.__eq__ (self, QTransform)

]($docs-qtransform.html)

  1. QTransform QTransform.__iadd__ (self, float num)

  1. QTransform QTransform.__idiv__ (self, float div)

  1. QTransform QTransform.__imul__ (self, QTransform)

  1. QTransform QTransform.__imul__ (self, float num)

  1. QTransform QTransform.__isub__ (self, float num)

  1. QTransform QTransform.__mul__ (self, QTransform o)

  1. QTransform QTransform.__mul__ (self, float n)

[

  1. bool QTransform.__ne__ (self, QTransform)

]($docs-qtransform.html)

  1. QTransform QTransform.__sub__ (self, float n)