GraphicsView的旋转,放缩

来源:互联网 发布:2017年最新java面试题 编辑:程序博客网 时间:2024/05/18 22:50

视图可以通过矩阵 QMatrix 设置放缩,旋转;

一般的方式可以直接放缩图像大小本身; 旋转可以旋转图像显示,而不是矩阵变化;

在Qt , GDI+等多种绘图方式中,矩阵方式概念变化图像,是图像变化的一种高级方式;


// extern GraphicsView *   graphicsView; 

void setupMatrix()
{
    qreal scale = qPow(qreal(2), (zoomSlider->value() - 250) / qreal(50));


    QMatrix matrix;

    matrix.scale(scale, scale);                   // 放缩;

    matrix.rotate(rotateSlider->value());   //旋转;


    graphicsView->setMatrix(matrix);
    setResetButtonEnabled();

}


以下是对QMatrix 的描述,具体可以参考帮助文档;

Detailed Description


The QMatrix class specifies 2D transformations of a coordinate system.


A matrix specifies how to translate, scale, shear or rotate the coordinate system, and is typically used when rendering graphics. QMatrix, in contrast to QTransform, does not allow perspective transformations. QTransform is the recommended transformation class in Qt.


A QMatrix object can be built using the setMatrix(), scale(), rotate(), translate() and shear() functions. Alternatively, it can be built by applying basic matrix operations. The matrix can also be defined when constructed, and it can be reset to the identity matrix (the default) using the reset() function.


The QMatrix class supports mapping of graphic primitives: A given point, line, polygon, region, or painter path can be mapped to the coordinate system defined by this matrix using the map() function. In case of a rectangle, its coordinates can be transformed using the mapRect() function. A rectangle can also be transformed into a polygon (mapped to the coordinate system defined by this matrix), using the mapToPolygon() function.


QMatrix provides the isIdentity() function which returns true if the matrix is the identity matrix, and the isInvertible() function which returns true if the matrix is non-singular (i.e. AB = BA = I). The inverted() function returns an inverted copy of this matrix if it is invertible (otherwise it returns the identity matrix). In addition, QMatrix provides the determinant() function returning the matrix's determinant.


Finally, the QMatrix class supports matrix multiplication, and objects of the class can be streamed as well as compared.

原创粉丝点击