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

    Question QgraphicsView/Scene to PNG image

    Hi All,

    My application consists of QGraphicsView/Scene nad I have added QGraphicsItems of different shapes line rectangle, circle etc. etc.
    I want to convernt whatever is in QGraphicsScene to image file (e.g. scene.png).
    Can you tell how to do this ???
    I have tried 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 
    But above code only creates png file with background image (which I draw in
    QGraphicsScene:drawBackground(QPainter * painter, QRectF const & /*clip*/) { } method using QPainterPath class.
    The items which I added doesnt get added in png file.
    Can you anybody tell me what I am missing ??

    Thanks in advance.
    Nilesh

  2. #2
    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: QgraphicsView/Scene to PNG image

    At what cordinates are your items ? are they within the 1024x768 rect in the scene ?

  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 have set scene rect's as (0, 0, 550, 700).
    I want entire scene should get saved as a image.

  4. #4
    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: QgraphicsView/Scene to PNG image

    (0, 0, 550, 700). seems ok.
    try changing image format from ARGB32premultiplied to some other and check if it works.

Similar Threads

  1. QGraphicsView/Scene and QTransform
    By rubenvb in forum Newbie
    Replies: 0
    Last Post: 24th December 2009, 11:04
  2. can I get another QGraphicsView's scene?
    By sincnarf in forum Qt Programming
    Replies: 1
    Last Post: 28th June 2007, 21:41
  3. How to use QGraphicsView and Scene right ...
    By Mike in forum Qt Programming
    Replies: 6
    Last Post: 22nd January 2007, 08:51
  4. Windows XP and QGraphicsView/Scene
    By maxpower in forum Qt Programming
    Replies: 7
    Last Post: 9th January 2007, 21:34
  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
  •  
Qt is a trademark of The Qt Company.