Results 1 to 6 of 6

Thread: in QGraphicsScene matrix of other QGraphicsScene

  1. #1
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default in QGraphicsScene matrix of other QGraphicsScene

    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

  2. #2
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: in QGraphicsScene matrix of other QGraphicsScene

    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

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: in QGraphicsScene matrix of other QGraphicsScene

    Well you can render each scene to some paintdevice / pixmap.
    Then join these pixmaps into one pixmap... hint : QPainter::drawPixmap

  4. #4
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: in QGraphicsScene matrix of other QGraphicsScene

    Quote Originally Posted by aamer4yu View Post
    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, 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);
    }
    Last edited by Noxxik; 14th February 2009 at 17:27.

  5. #5
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: in QGraphicsScene matrix of other QGraphicsScene

    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 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

    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)

  6. #6
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: in QGraphicsScene matrix of other QGraphicsScene

    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?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.