我是靠谱客的博主 默默可乐,最近开发中收集的这篇文章主要介绍GraphicsView的旋转,放缩,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

视图可以通过矩阵 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.

最后

以上就是默默可乐为你收集整理的GraphicsView的旋转,放缩的全部内容,希望文章能够帮你解决GraphicsView的旋转,放缩所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(37)

评论列表共有 0 条评论

立即
投稿
返回
顶部