Results 1 to 4 of 4

Thread: QPixmap in GraphicsView ??

  1. #1
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QPixmap in GraphicsView ??

    I have been trying to get a image to show in a GrapichsView.
    But after alot of trail and error I have not got it to work.
    Would anyone be so kind to point me in the right direction?

    Qt Code:
    1. ui->graphics_ImgLib->setScene(&scene);
    2.  
    3. QPixmap image;
    4. image.load(":/IMG/IMG/logo.png");
    5. scene.addPixmap(image);
    6.  
    7. QGraphicsPixmapItem pixMapItem;
    8. pixMapItem.setPixmap(image);
    9.  
    10. scene.addItem(&pixMapItem);
    11. ui->graphics_ImgLib->show();
    To copy to clipboard, switch view to plain text mode 

    Thanks for any help.

    Cheers
    WetCode

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPixmap in GraphicsView ??

    What is the scope of the QGraphicsScene instance? My guess is that "scene" is going out of scope immediately or the pixmap is not in the resource file location you think it is.

  3. #3
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QPixmap in GraphicsView ??

    I am wery certen the image is there as i am displaying it several places.
    When you say out of scope, do you mean its not within the QGrapichsView ?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPixmap in GraphicsView ??

    No, I mean scope of time over which the QGraphicsScene object exists. If you create the scene on the stack (as in your example) the object ceases to exist when the variable goes out of scope (i.e. usually at the end of the enclosing { } block). When the scene is destroyed the view has nothing to display, and that's what you see. The QGraphicsScene must exist as long as the view needs to display it.

    This is generic C++ and not specific to Qt.

Similar Threads

  1. Replies: 4
    Last Post: 17th July 2013, 17:47
  2. Replies: 4
    Last Post: 28th August 2008, 13:13
  3. Replies: 1
    Last Post: 21st August 2008, 07:44
  4. Replies: 5
    Last Post: 9th April 2007, 14:26
  5. QT GraphicsView Help
    By mistertoony in forum Qt Programming
    Replies: 15
    Last Post: 15th February 2007, 04:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.