• 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支持的变换更丰富了~

    具体的功能可以看下图:

     

  • 相关阅读:
    UVALive 7456 Least Crucial Node (并查集)
    UVALive 7454 Parentheses (栈+模拟)
    HDU 5778 abs (枚举)
    HDU 5776 sum (模拟)
    HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)
    HDU 5805 NanoApe Loves Sequence (模拟)
    HDU 5734 Acperience (推导)
    HDU 5842 Lweb and String (水题)
    HDU 5833 Zhu and 772002 (高斯消元)
    HDU 5835 Danganronpa (贪心)
  • 原文地址:https://www.cnblogs.com/MakeView660/p/10370947.html
Copyright © 2020-2023  润新知