Results 1 to 3 of 3

Thread: problem with QGraphicsPixmapItem

  1. #1
    Join Date
    Nov 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Question problem with QGraphicsPixmapItem

    Hello everyone,
    I am trying to display an image using QGraphicsView but all I get is a blank window.
    Here is the code:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv)
    4. QGraphicsScene* scene = new QGraphicsScene(QRect(0, 0, 600, 400));
    5. QPixmap Pix("king.png");
    6. //does not work either
    7. //QGraphicsPixmapItem *item1 = scene->addPixmap(Pix);
    8. scene->addItem(item);
    9. view.setScene(scene);
    10. view.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    I think that I'm missing something obvious, but still I'm unable to find it on my own.
    Any suggestions?

  2. #2
    Join Date
    Nov 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: problem with QGraphicsPixmapItem

    solved.
    Relative path does not work for me. Had to use absolute path.
    Qt Code:
    1. QPixmap Pix("/home/justas/graphics_view_test/king.png");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with QGraphicsPixmapItem

    Relative paths depend on the current working directory of the application.

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 21st February 2014, 06:14
  2. QGraphicsPixmapItem
    By erfan in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2012, 21:54
  3. Replies: 7
    Last Post: 21st January 2011, 19:53
  4. problem with Qgraphicspixmapitem
    By skab in forum Newbie
    Replies: 3
    Last Post: 23rd October 2010, 09:54
  5. Replies: 3
    Last Post: 22nd August 2010, 09:23

Tags for this Thread

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.