Results 1 to 6 of 6

Thread: How to show items in the same position saved in QGraphicsView/Scene ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    9
    Qt products
    Qt4

    Default How to show items in the same position saved in QGraphicsView/Scene ?

    Hi to all,
    I'm having trouble showing the image saved in a QGraphicsScene. I need to save multiple image items in QGraphicsView and reload them to do something. My solution is to save each item as an independent image file and write down each scene position into a record for loading. In my process, if the GraphicsView has the same size in saving/loading, image files can be loaded and shown in the same position as they saved. But if I use a larger/smaller window to load images, the images are not located in the same position (corresponding to the top-left corner of the view).

    My saving process
    Qt Code:
    1. QTextStream ts(&file);
    2. ..
    3. QGraphicsPixmapItem* it = qgraphicsitem_cast<QGraphicsPixmapItem*>(scene()->items().at(i));
    4. tag = QString("%1/%2.png").arg(path).arg(i); // filename
    5. It->pixmap (). save (tag); // save image item
    6. ts << "\t\t" << it->x() << " " << it->y() << " " << tag << "\n"; // save the scene position and the file name
    To copy to clipboard, switch view to plain text mode 


    My loading process
    Qt Code:
    1. QTextStream ts(&file);
    2. ..
    3. ts >> x >> y >> tag;
    4. QImage img(tag); // read the image by filename
    5. QGraphicsPixmapItem* item = new QGraphicsPixmapItem(pixmap, 0, scene());
    6. item->setPos(x, y);
    To copy to clipboard, switch view to plain text mode 

    It's sorry that I have no idea about it. Thank you.

    The image file saved in a small window.
    pos_smallwnd.jpg

    After loading, the image seems moved
    pos_largewnd.jpg

    What I want .. located at fixed position to the top-left corner of GraphicsView
    pos_I_want.jpg
    Last edited by chiaminhsu; 12th November 2013 at 09:38.

Similar Threads

  1. QGraphicsview - how to organize scene and items
    By metRo_ in forum Qt Programming
    Replies: 0
    Last Post: 10th April 2012, 00:39
  2. QGraphicsView - show mouse cursor position in status bar
    By mwgobetti in forum Qt Programming
    Replies: 5
    Last Post: 19th November 2011, 18:34
  3. Cursor Position in scene
    By rogerholmes in forum Newbie
    Replies: 2
    Last Post: 12th March 2010, 15:31
  4. Position of Items in QGraphicsScene/QGraphicsView
    By StefanK2 in forum Qt Programming
    Replies: 11
    Last Post: 7th July 2009, 14:04
  5. Cursor scene position
    By xgoan in forum Qt Programming
    Replies: 1
    Last Post: 26th December 2006, 13:51

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
  •  
Qt is a trademark of The Qt Company.