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