【发布时间】:2017-07-24 19:58:33
【问题描述】:
我有一个普通的 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);
【问题讨论】:
-
“它们不起作用”是什么意思?您是否看到像素图并且它没有被定位,或者您什么也没看到?