繁体   English   中英

在Qt5中更改QGraphicsScene / View中的Pixmap位置

[英]Change Pixmap Position in QGraphicsScene/View in Qt5

我有一个普通的QGraphicsView / QGraphicsScene,我要做的就是将QPixmap(.png)加载到图形中并手动设置该QPixmap图像的位置。 我找到了解决方案,但它们在Qt5上不起作用。 关于如何在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);

如果您在实现中使用QGraphicsPixmapItem,或者实际上在任何Qt对象中使用QGraphicsPixmapItem,则需要将其包含在cpp中:-

#include <QGraphicsPixmapItem>

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM