Using QWidget vs. QGraphicsItem?
-
My objective: I want to load multiple images from a folder and for each of them I want to draw / paint movable and resizable graphics objects on it and then save the edited images (containing the graphics objects).
My questions are:
-
I can load multiple images easily using QWidget (extending class QLabel). But is there a way to do so using QGraphicsScene? Which one is better for processing and saving each image separately?
-
Is it possible to use QWidget to load an image and use QGraphicsScene to draw movable and resizable object on the image and still save "the image with the object" together? Or there is a better way to do this?
-
-
[quote author="soumipaul" date="1351942702"]
My questions are:-
I can load multiple images easily using QWidget (extending class QLabel). But is there a way to do so using QGraphicsScene? Which one is better for processing and saving each image separately?
-
Is it possible to use QWidget to load an image and use QGraphicsScene to draw movable and resizable object on the image and still save "the image with the object" together? Or there is a better way to do this?[/quote]
- You can draw to QWidget using QPainter. Using QLabel is a bad choice (based from my experience, it lags when editing an image while using QLabel to draw it using setpixmap() in my project -"YASCU-Qt":http://sourceforge.net/projects/yascuqt/ I already made a lot of changes on it but I can't post latest development yet). When it comes to multiple images, Qt has a number of container classes (QList, etc....) and try using QList<QPixmap> or QList<QImage>.
2 QGraphicsScene can be viewed only with a QGraphicsView, I have no idea if somebody was able to view it using QWidget only but I think it is possible. I can't recommend it since I think the coding is very difficult.
-
-
Thanks for your reply.
However, my questions were
- what is the best way to draw a resizable-movable figure (e.g., a rectangle) on a loaded image?
- Is it possible to save the loaded image and the newly-drawn resizable-movable object together as a single image by QGraphicsScene (without using QWidget)? If not, what is the best way to do this?
Of course I want to repeat this procedure on the list of images one by one.
-
You could simply put the image into a GraphicsScene, add the rectangle (or whatever) on top of it, and render the whole scene into a new Pixmap.
Something like this:
@
QPixmap resultPixmap(resultPixmapSize);
QPainter painter(&resultPixmap);// Render the whole scene
pScene->render(&painter,QRectF(), sourceRect);
@You can also specify only to render a part of the scene. The result ends up in resultPixmap, and you can go from there.