PDA

View Full Version : Screenshot only for the rect of certain items on the scene



afail
25th June 2009, 16:53
Hi,

I am trying to make a screenshot/Pixmap out of certain graphicItems on a QGraphicsScene object like this:



QGraphicsItemGroup* itemGroup = new QGraphicsItemGroup(0);

foreach(QPointer<ListOfItems> item, itemsToPrint.list())
{
itemGroup->addToGroup(item);
}

QRectF selectionRect = itemGroup->boundingRect();
QPixmap image(selectionRect.width(), selectionRect.height());


Then render the image and I hoped that it will render/print in the screenshot only the items I need to. But instead of that, the screnshot that is created is fuzzy (nothing visible is shown properly), and the items from the main scene disappear :eek:

How can I make screenshot of part of the scene over the boundingRect of items that match some criteria? any example on this?

thanks

wysota
25th June 2009, 22:09
Now you are creating an empty pixmap (with undetermined contents) that is the size of the selection. You probably want to use QGraphicsScene::render()

afail
26th June 2009, 07:24
ok, but why the topics do disappear when I add them to qgraphicsgroupitem object? :S

wysota
26th June 2009, 08:09
Because the group is not part of the scene. I'm not sure why you're adding that group in the first place.

afail
26th June 2009, 10:11
Well... how can I get the boundingRect only for the items on the scene that match my criteria? :/ I don't need a boundingRect for all of the items on the scene, just for some of them..

Even if I create new QGraphicsScene object and then add these items via QGraphicsScene::addItem(..) the topics disappear :s.

isn't there any example on this matter? thanks wysota.

wysota
26th June 2009, 10:22
Well... how can I get the boundingRect only for the items on the scene that match my criteria?
Unite the rects of all interesting items.

afail
26th June 2009, 15:15
Ok I hope this is my last reply since I am not getting the needed results, but I am close to it.



QRectF shotRect = item.current().boundingRect();
foreach(ItemType item, itemsList)
{
shotRect = shotRect.united(item->boundingRect());
}


now, as I read in the doc, shotRect should unite all of the rects that are in the itemsList list object. But it always has the value of the rect of biggest item on the scene. which is not what I need. what am I not doing right?

thanks sorry (graphics seem a little heavy for me :( )

wysota
26th June 2009, 19:33
The code seems correct. Please provide a minimal compilable example reproducing the problem - then we can work on it to find the problem on your side.