QT QTransform与QMatrix 有啥区别?

刚开始学习QT,我使用的是QT5.12进行开发,要不时地查阅QT的官方帮助文档~

仔细阅读QT官方帮助QTransform类以及QMatrix类,发现两个类的作用描述一模一样(“The QTransform class specifies 2D transformations of a coordinate system.”以及“The QMatrix class specifies 2D transformations of a coordinate system.”),它们两者有什么区别呢?

@

// Old code

QMatrix m;

m.translate(point.x(), point.y());

m.scale(-1.0, 1.0);

m.translate(-point.x(), -point.y());

item->setMatrix(m, true);

@

@

// New code

QTransform transform;

transform.translate(point.x(), point.y());

transform.scale(-1.0, 1.0);

transform.translate(-point.x(), -point.y());

item->setTransform(transform);

@

 

可能在QT4版本中使用QMatrix多一些,QT5中可能新引入了QTransform,所以在新版本的QT开发中更推荐使用QTransform!

QTransform 与 QMatrix 不同之处在于,它是一个真正的 3x3 矩阵,允许视角转换,QTransform 的 toAffine() 方法允许将 QTransform 转换到 QMatrix。如果视角转换已在矩阵指定,则转换将导致数据丢失。

QMatrix:   

                                                          

QTransform:

可见,对于QMatrix,m13和m23总是0,m33总是1,而这些元素在QTransform却是为了投影变换(projection transformation)来使用,可见QTransform相比于QMatrix支持的变换更丰富了~

具体的功能可以看下图:

 

转载于:https://www.cnblogs.com/MakeView660/p/10370947.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值