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
..
tag
= QString("%1/%2.png").
arg(path
).
arg(i
);
// filenameIt->pixmap (). save (tag); // save image item
ts << "\t\t" << it->x() << " " << it->y() << " " << tag << "\n"; // save the scene position and the file name
QTextStream ts(&file);
..
QGraphicsPixmapItem* it = qgraphicsitem_cast<QGraphicsPixmapItem*>(scene()->items().at(i));
tag = QString("%1/%2.png").arg(path).arg(i); // filename
It->pixmap (). save (tag); // save image item
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
..
ts >> x >> y >> tag;
QImage img
(tag
);
// read the image by filename item->setPos(x, y);
QTextStream ts(&file);
..
ts >> x >> y >> tag;
QImage img(tag); // read the image by filename
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(pixmap, 0, scene());
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
Bookmarks