在QGraphicsScene中的特定坐标中的位置和图像
问题描述:
在下面的代码中,我使用了item.setPos(0,0);
以便将green.png
放置在我的应用程序的左上角(实际上为QGraphicsView
)。但是从两个方向出现在* - 垂直和水平。请帮助将图像放入0,0坐标。在QGraphicsScene中的特定坐标中的位置和图像
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QIcon>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setBackgroundBrush(QBrush(QColor(255, 255, 255), Qt::SolidPattern));
QGraphicsPixmapItem item(QPixmap(":/images/green.png"));
item.setPos(0,0);
scene.addItem(&item);
QGraphicsView view(&scene);
view.setFixedSize(400, 400);
view.setWindowTitle("Diamond Dash");
view.setWindowIcon(QIcon(":/images/red.png"));
view.show();
return app.exec();
}
答
我已经加入
scene.setSceneRect(0,0, 400, 400);
和它的工作!