Results 1 to 4 of 4

Thread: QGraphicsView/Scene to png image

  1. #1
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsView/Scene to png image

    Hi All
    My application consists of QGraphicsView/Scene with some shapes like rectange items.
    I have option to save entire scene to an image file using following code
    Qt Code:
    1.  
    2. scene->addItem(rectItem);
    3. scene->addItem(rectItem);
    4. //.....
    5.  
    6. QImage img(1024,768,QImage::Format_ARGB32_Premultiplied);
    7. QPainter p(&img);
    8. scene.render(&p);
    9. p.end();
    10. img.save("scene.png");
    To copy to clipboard, switch view to plain text mode 

    Image is gets saved propertly. but when I tried to zoom in GraphicsView by setting matrix. and then save the image, tthe image which I get is of initial scale level.
    e..g Initial scale is 1 after zoom in say GraphicsView's scale becomes 2
    but image (scene.png) is created with initial scale of 1.

    Can any body tell what I missing ??
    Thanks in advance.

    Nilesh

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView/Scene to png image

    You are saving an image with a fixed size always:
    Qt Code:
    1. QImage img(1024,768,QImage::Format_ARGB32_Premultiplied);
    To copy to clipboard, switch view to plain text mode 

    You have to calculate the correct image size for the zoomed scene.

    [EDIT]:
    Oh, I see now what you mean.
    You want a fixed size image, and only the zoomed part of the scene in it.
    You have to draw the visible scene rect in to the image then.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView/Scene to png image

    I want entire zoomed scene should get saved as an image. But even the scene items are zoomed in, and then saving image I am getting image of initial zoom scale.

    What is the solution for this ??

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView/Scene to png image

    The scene object is not a visible object.
    It only holds information about the proportions of its consents (very simply put).

    If you want the whole scene in the QImage, and you want it scaled, then resize the QImage.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QgraphicsView/Scene to PNG image
    By nileshsince1980 in forum Qt Programming
    Replies: 3
    Last Post: 6th May 2010, 08:18
  2. QGraphicsView/Scene and QTransform
    By rubenvb in forum Newbie
    Replies: 0
    Last Post: 24th December 2009, 11:04
  3. can I get another QGraphicsView's scene?
    By sincnarf in forum Qt Programming
    Replies: 1
    Last Post: 28th June 2007, 21:41
  4. How to use QGraphicsView and Scene right ...
    By Mike in forum Qt Programming
    Replies: 6
    Last Post: 22nd January 2007, 08:51
  5. Possible QGraphicsView/Scene bug
    By Corran in forum Qt Programming
    Replies: 1
    Last Post: 30th December 2006, 01:47

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.