【问题标题】:Place and image in specific coordinates in QGraphicsScene在 QGraphicsScene 中的特定坐标中放置和图像
【发布时间】:2013-04-24 06:42:16
【问题描述】:

在下面的代码中,我使用item.setPos(0,0);green.png 放在我的应用程序的左上角(实际上是QGraphicsView)。但是它从两个方向(垂直和水平)都出现在中心。请帮忙把图片放在0,0坐标。

#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();
}

【问题讨论】:

    标签: c++ qt qgraphicsview qgraphicsscene


    【解决方案1】:

    我已经添加了

    scene.setSceneRect(0,0, 400, 400);
    

    它成功了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-10
      • 1970-01-01
      • 1970-01-01
      • 2021-03-01
      • 2013-08-07
      • 2014-02-18
      • 2021-12-25
      • 1970-01-01
      相关资源
      最近更新 更多