Results 1 to 5 of 5

Thread: Can't get pixmap to show up in QGraphicsView

  1. #1
    Join Date
    Jan 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Can't get pixmap to show up in QGraphicsView

    Hello -

    For some reason I can't get a pixmap to show up in a QGraphicsView on my form. I am using Qt 4.7.1. Here is my code:

    QPixmap pixMap("C:/Stuff/Projects/myImage.jpg");

    QGraphicsScene scene;
    scene.addPixmap(pixMap);
    ui.graphicsView->setScene(&scene);
    ui.graphicsView->show();

    What am I missing / doing wrong?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Can't get pixmap to show up in QGraphicsView

    Can you show jpeg's at all? E.g. on a QLabel? Do you have the requires image plugins?

    Also do you see anything on the view? Because I guess it is because you create the scene on the stack, not on the heap... That would be a basic C++ error.

  3. #3
    Join Date
    Jan 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't get pixmap to show up in QGraphicsView

    Yep, you are right...duh. My scene was being deleted. All is good now. Thanks.

  4. #4
    Join Date
    Apr 2011
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Can't get pixmap to show up in QGraphicsView

    Dear friends , i can't understand clearly what is meant by image plugins or what you mean by you declared the scene in the stack?

    i have the same problem and the image is not displayed
    thanks

  5. #5
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Qt products
    Qt4
    Platforms
    Symbian S60
    Thanks
    38
    Thanked 19 Times in 19 Posts

    Default Re: Can't get pixmap to show up in QGraphicsView

    "In the stack" means you are creating the scene statically.

    Basically:

    QGraphicsScene scene;

    instead of

    QGraphicsScene scene = new QGraphicsScene();

    If you write it without the "new" operator, it's deleted when it reachs the end of the scope (the end of the function, in this case) So you are creating a scene, adding a QGraphicsPixmapItem and deleting the whole scene when the function ends.
    If you use the second option the scene is stored in the dinamic memory, so it's not deleted.

    If it does not help you, please provide some code.

Similar Threads

  1. Replies: 3
    Last Post: 16th April 2010, 07:56
  2. Replies: 6
    Last Post: 13th January 2010, 18:44
  3. QGraphicsView + OpenGL -> Pixmap rendering issue
    By JoergRe in forum Qt Programming
    Replies: 2
    Last Post: 20th May 2008, 18:41
  4. Smooth pixmap transform in QGraphicsView problem
    By spud in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2007, 16:47
  5. [B]How to show Pixmap on QMenuBar??[/B]
    By bigbigmoon in forum Newbie
    Replies: 2
    Last Post: 17th April 2007, 06:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.