Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Placing an image in GraphicsScene
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Placing an image in GraphicsScene

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxg0
    wrote on last edited by
    #1

    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"));
    item.setPos(0,0);
    scene.addItem(&item);
    
    
    QGraphicsView view(&scene);
    view.setFixedSize(400, 400);
    view.show();
    

    }

    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
    Tx

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxg0
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved