PDA

View Full Version : QGraphicsItems Layers



qtuser20
22nd July 2009, 22:43
Hi All

I am using QGraphics framework for an application to display images and add text, shapes and items over the image. QGraphics framework seems to be a right fit for my need, because i need to allow all the items to be repositioned and editable/ show/hide items etc.

The challenge however is when i save the image, i do not want the text/items to be burned in.This happens when i render using QPainter.
While saving the image, i need to save the user created items as a separate layer and preserve the original image.Similarly , when i reload the image, i want to load back the items layer separately, only on demand.

Could somebody provide suggestions if QGraphics Framework has existing capability to support this ? I would really appreciate any hints. Thank you !

wysota
22nd July 2009, 23:06
hide() or show() respective items before saving data from the scene.

qtuser20
22nd July 2009, 23:22
Thanks for the answer. I think i should explain the problem better.

Hide()/Show() can be used while the image is currently loaded. But, when i save the image, the text/items are burned into the image.I can use hide() and save only the image, but subsequently when i reload the image, i need to have access to the created items.

I am hoping there would be a way to save the item layer as a separate format/file, and while recalling the original image if the user likes to view the items, load the item layer also, else load only the image.

Else, am i missing something ? Would really appreciate feedback.

wysota
22nd July 2009, 23:36
I can use hide() and save only the image, but subsequently when i reload the image, i need to have access to the created items.
Save them in another file and reload when you need them.

qtuser20
23rd July 2009, 21:10
Hi

Instead of loading them as separate images, is there a way to overlay or combine them , so that this process is not transparent to the user .

Thanks

wysota
23rd July 2009, 21:56
Overlay or combine into what? You need a file to save to. You either save your image as image and the rest as a separate file or you save everything in one file, losing direct access to the image.

qtuser20
23rd July 2009, 23:08
For the save operation, i initially hide() the items and save out the image A.

Then, i show() the items and use setbackgroundbrush to white to save out only the items file. Lets call this image B.I do this because image files are larger and would be better to store only items.

When i load back image A, i would like to have a menu control that allows user to choose the items file. When the user loads image B , the contents of items should appear over image A.ie it should appear as if the items are drawn over image A .

I think i should not be using setbackgroundbrush(Qt:white) to store the items file.Is there an alternative suggestion?

Thankyou

wysota
24th July 2009, 00:21
If you don't need to do anything with the items after reloading them then you can make the image an item as well and hide the item before saving other items. Graphics scene is by default transparent so you'll get a proper effect (alternatively set the background brush to transparent colour). When reloading, load the two saved images as items.

This only makes sense if you don't want to interact with the items after reloading them. I would suggest to do something else. Use your own binary format to save both the image and the items into a file so that you can later reload both the image and the items (as items, not as a bitmap) and in addition to that provide an export functionality to save the background (and possibly other items if the user wants to) as image file.