PDA

View Full Version : in QGraphicsScene matrix of other QGraphicsScene



Noxxik
12th February 2009, 19:00
Hi I am starting with QT, so I would like to ask you about my problem.
I have:
QGraphicsScene *scene;

into scene I painted some objects (rectangles, triangles etc.). At the end I would like to save this scene for example 4times to pdf document (It should create matrix with 2 rows and 2columns)
Can you help me someone? I will be happy

now I have something this:

QPainter painter(&printer);
scene->render(&painter); /* scene QGraphicsScene */


but it creates only 1 scene into pdf document

Noxxik
13th February 2009, 12:10
anyone who knows? I am unhappy. I want to QGraphiscScene A consists of other QGraphiscScene B
Does someone know? Please give mi advice or some hint or something else

aamer4yu
13th February 2009, 17:09
Well you can render each scene to some paintdevice / pixmap.
Then join these pixmaps into one pixmap... hint : QPainter::drawPixmap

Noxxik
14th February 2009, 17:14
Well you can render each scene to some paintdevice / pixmap.
Then join these pixmaps into one pixmap... hint : QPainter::drawPixmap
thank you a lot ;) I tried it :) and it is OK, but I have to have vector graphics no bitmaps. So I found THIS (http://doc.trolltech.com/4.4/qgraphicsscene.html#items), but I have problem. I have this code

QGraphicsScene newScene;
newScene.setSceneRect(QRectF(0, 0, 600, 1000));
QList<QGraphicsItem *> items = scene->items(QRectF(xCard,yCard,widthCard,heightCard), Qt::IntersectsItemShape);

qreal height=0;
for(int i=0;i<2;i++){
foreach (QGraphicsItem *newItem, items) {
QPointF position=newItem->pos();
newItem->setPos(position.x(), position.y()+height);
newScene.addItem(newItem);
}
height+=heightCard;
}

I want to make column of my scene in newScene, but this code make me only 1 and last scene onto newScene.
Could someone help me, where is mistake?
thanks a lot ;)

EDIT: this code paint anything to my pdf

this code paint onto pdf scene only once.

QGraphicsScene newScene;
newScene.setSceneRect(QRectF(0, 0, 600, 1000));
QList<QGraphicsItem *> items = scene->items(QRectF(xCard,yCard,widthCard,heightCard), Qt::IntersectsItemShape);

foreach (QGraphicsItem *newItem, items) {
QPointF position=newItem->pos();
newItem->setPos(position.x(), position.y());
newScene.addItem(newItem);
}

Noxxik
15th February 2009, 13:35
I think, that problem is in QList, which is returned in QGraphicsScene::items(), isnt, it?
I tried this, too.

for(int i=0;i<items.size();i++){
items2 << items[i]; // try to copy qlist
int height=0;
for(int j=0;j<3;j++){
QGraphicsItem *newItem=items[i];
QPointF position=newItem->pos();
newItem->setPos(position.x(), position.y()+height);
newScene.addItem(newItem);
height+=int(heightCard);
}
// newScene.update(QRectF(0, 0, 900, 1000));
}

but any changes :eek: Can someone tell me, how I can copy QList? It paints only the last scene, but I want to have 3 scene not only one :crying:

I dont create in constructor 2 scenes (one, which is visible and other which is invisible and paint onto both scenes at same moment - I think, that this situation could be hard for RAM and CPU)

Noxxik
15th February 2009, 17:27
So I tried everything and I get information, that in
QList<QGraphicsItem *> items = scene->items(QRectF(xCard2,yCard2,widthCard2,heightCard2) , Qt::IntersectsItemShape);
I should allocate each element of QList for each new scene again, but when I tring to allocate
QGraphicsItem *myItem = new QGraphicsItem(items.front());
compiler writes, that I cannot allocate object QGraphicsItem, because there are some virtual functions, which are abstract.
Now I have not got any idea, which I can try.
Can anybody help me?