[SOLVED] Placing an image in GraphicsScene

  • I am trying to use a *.png" file to load an image in GraphicsScene and from here onto my basic Widget. Here is the code I am using:

    int main(int argc, char **argv)

    QApplication app(argc, argv);
    QGraphicsScene scene;
    scene.setBackgroundBrush(QBrush(QColor(255, 255, 255), Qt::SolidPattern));

    QGraphicsPixmapItem item(QPixmap("needle.png"));
    QGraphicsView view(&scene);
    view.setFixedSize(400, 400);


    However, I get the window but no evidence of the image that comes with "needle.png". Why?
    It is as if the file is not taken into account at all, as if I introduce an error in the fielpath, the application still builds!

    Any help would be very much appreciated

  • Moderators

    are you sure your image is present? Meaning relatively to the working directory?
    You can either try to use qrc or an absolute path to make sure.

    Edit: oh yes... and use code tags ('@') please

  • Problem solved.

    As I am deploying my application on a target platform. I simply had to provide the file there in the run-time environment.

    Nothing to do with Qt.

    The code is therefore correct.

    Apologies for the confusion.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.