Results 1 to 10 of 10

Thread: ScrollArea save as image

  1. #1
    Join Date
    Jul 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Post ScrollArea save as image

    Hi

    I have several "curves" (as seen in the attached picture) these curves are contained in a QVBoxLayout and this in turn is contained in a QScrollArea.

    my question is, is there any way to keep these "curves" as an image file? ie jpg, png, tiff, etc..

    curve.jpg

  2. #2
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollArea save as image

    Yea this should be possible
    try rendering the widget
    QPixmap pixmap(rectangle->size()); //change size to the size of the curves
    widget->render(&pixmap, QPoint(), QRegion(rectangle));

    get the internal widget from the QVBoxLayout and render it


    Added after 7 minutes:


    I tried it and it works like a charm, i used pixmap.save(filename); to save the image
    Last edited by StrikeByte; 21st August 2012 at 14:29.

  3. #3
    Join Date
    Jul 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ScrollArea save as image

    who is rectangle?? who is a widget???

    I am putting it to you as ScrollArea widget and you have a QWidget as a rectangle that is contained in the ScrollArea and does not work

    You can post the code that you worked?

  4. #4
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollArea save as image

    What type is the curve? is it inherited from QWidget?

    this is the code I used:
    Qt Code:
    1. QPixmap pixmap(pushbutton->rect().size());
    2.  
    3.  
    4. pushbutton->render(&pixmap,QPoint(),QRegion(pushbutton->rect()));
    5. pixmap.save("c:/test.png");
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jul 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ScrollArea save as image

    is a bit complicated ... The curves are a QGraphicsView ... as are several curves put them inside a QVBoxLayout ... And how could place the direct layout ScrollArea because not trigger the scrollbar, I had to put the layout in a Qwidget this widget and put it in the ScrollArea.

    I'm doing well ... and does not work


    Qt Code:
    1. QPixmap pixmap(scroll->rect().size());
    2.  
    3. scroll->render(&pixmap,QPoint(),QRegion(scroll->rect()));
    4. pixmap.save("D:/test.png");
    To copy to clipboard, switch view to plain text mode 
    Last edited by jackajack01; 21st August 2012 at 16:27.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ScrollArea save as image

    So, you need to render
    ...I had to put the layout in a Qwidget this widget..
    as StrikeByte said.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollArea save as image

    Then u need to render the QWidget that you placed inside the scrollarea

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ScrollArea save as image

    To simplify this task use QScrollArea::widget.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Jul 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ScrollArea save as image

    I'm sorry, I'm hard of understanding today. not referred to render the QWidget. I'm doing this and not working


    Qt Code:
    1. scroll = new QScrollArea();
    2. wid = new QWidget(scroll);
    3. layout = new QHBoxLayout(wid);
    4.  
    5.  
    6. QPixmap pixmap(wid->rect().size());
    7. wid->render(&pixmap,QPoint(),QRegion(wid->rect()));
    8. pixmap.save("D:/test.png");
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollArea save as image

    [WIKI][/WIKI]If you use the code from your last post it is normal that there is no picture.
    The widget doesn't have a size and there is nothing to show

    try this code
    Qt Code:
    1. scroll = new QScrollArea();
    2. wid = new QWidget(scroll);
    3. btn = new QPushButton("test",wid);
    4. wid->setGeometry(0,0,200,200);
    5. layout = new QHBoxLayout(wid);
    6.  
    7.  
    8. QPixmap pixmap(wid->rect().size());
    9. wid->render(&pixmap,QPoint(),QRegion(wid->rect()));
    10. pixmap.save("D:/test.png");
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to StrikeByte for this useful post:

    jackajack01 (24th August 2012)

Similar Threads

  1. Replies: 4
    Last Post: 30th May 2012, 00:37
  2. Qwt & save as image
    By giostau in forum Qwt
    Replies: 1
    Last Post: 8th February 2012, 15:41
  3. Save greyscale image
    By Lele in forum Qt Programming
    Replies: 8
    Last Post: 12th August 2008, 09:59
  4. is it possible to save a webpage as an image?
    By billconan in forum Qt Programming
    Replies: 2
    Last Post: 8th July 2008, 02:08
  5. save table as an image
    By ulmly in forum Qt Programming
    Replies: 4
    Last Post: 26th June 2008, 09:12

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.