欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Qt图形视图框架(五) 变换

程序员文章站 2024-03-26 09:48:53
...

变换

#include <QtWidgets>
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QGraphicsScene scene;
    QGraphicsView view(&scene);
    view.setSceneRect(0, 0, 500, 500);

    auto hello = new QGraphicsSimpleTextItem("Hello");
    scene.addItem(hello);

    //view.rotate(60);
    //view.translate(100, 100);

    //hello->setScale(2);
    //hello->setRotation(30);

    QTransform t = QTransform::fromScale(2, 4);
    t.shear(2, 3);
    auto rect = new QGraphicsRectItem(0, 0, 50, 50);
    rect->setTransform(t);
    rect->setPos(100, 100);
    scene.addItem(rect);

    view.show();
    return a.exec();
}