我有一个普通的 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);
您可以从计算机浏览图像并设置其位置。
以防万一,它可以帮助某人。
QString fileNamez = QFileDialog::getOpenFileName(this,"Open Filezzz","C:/");
QGraphicsPixmapItem *pm = scene->addPixmap( QPixmap(fileNamez) );
pm->setPos(xPos,yPos);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)