2014-10-07 194 views
2

我有一个正常的QGraphicsView/QGraphicsScene,我想要做的是将QPixmap(.png)加载到图形并手动设置该QPixmap图像的位置。我找到了解决方案,但它们不适用于Qt5。关于如何在Qt5上实现这一点的任何想法?谢谢。更改QGraphicsScene中的Pixmap位置/Qt5中的视图

QGraphicsScene* scene = new QGraphicsScene(QRect(0, 0, 600, 400)); 

QPixmap Pix(":/test.gif"); 

// doesnt work 
//Pix.setGeometry(QRect(-30, 40, 260, 200)); 


QGraphicsPixmapItem *item1 = scene->addPixmap(Pix); 

// doesnt work 
//item1->setPos(-25, 45); 
//scene->addPixmap(Pix)->setPos(0,0); 

//QGraphicsView* view = new QGraphicsView(ui->centralWidget); 

QGraphicsView* view = new QGraphicsView(this); 

view->setScene(scene); 
+0

你是什么意思“他们不工作”?你看到像素图,它没有被定位,或者你没有看到任何东西? – TheDarkKnight 2014-10-07 13:49:10

回答

0

如果您使用您的实施QGraphicsPixmapItem,或任何Qt的对象,你需要把它列入了CPP: -

#include <QGraphicsPixmapItem> 
+0

YUP! *弓* thx:) – 2014-10-07 14:21:46

+1

请点击答案左侧的打勾,接受最有帮助/正确的答案,谢谢:) – dom0 2014-10-07 14:25:13

0

您可以在计算机上浏览图像,并设置其位置。为了以防万一,它可以帮助某人。

 QString fileNamez = QFileDialog::getOpenFileName(this,"Open Filezzz","C:/"); 
     QGraphicsPixmapItem *pm = scene->addPixmap(QPixmap(fileNamez)); 
     pm->setPos(xPos,yPos); 
相关问题