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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chinabinlang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值