Qt 使用QGraphicsPixmapItem、QGraphicsScene、QMatrix 的QGraphicsView的显示,缩放


.h

1     QGraphicsScene *scene; 2     QGraphicsPixmapItem *theFrame; 3     QMatrix matrix;

.cpp

 1 MainWindow::MainWindow(QWidget *parent) :  2  QMainWindow(parent),  3     ui(new Ui::MainWindow)  4 {  5     ui->setupUi(this);  6    // 初始化
 7     scene = new QGraphicsScene(this);  8     theFrame = new QGraphicsPixmapItem();  9     theFrame->setFlag(QGraphicsPixmapItem::ItemIsSelectable, false); 10     theFrame->setFlag(QGraphicsPixmapItem::ItemIsMovable, false); 11     theFrame->setFlag(QGraphicsPixmapItem::ItemSendsGeometryChanges); 12 
13     scene->addItem(theFrame); 14 
15     scene->setSceneRect(0,0,4096,2160);//设置 scene 尺寸
16 
17     matrix.scale(0.1, 0.1); //缩放比例
18     ui->graphicsView->setMatrix(matrix); 19     ui->graphicsView->scale(1,-1); 20     ui->graphicsView->setScene(scene); 21     ui->graphicsView->show(); 22 }

刷新图像

theFrame->setPixmap(Pixmap);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM