Results 1 to 12 of 12

Thread: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

  1. #1
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    Hello! Friends,
    I am working with Qt4.3 on WinXp. I have a application with qwtplot to draw curves of my application. Now i want to save/convert the drawn qwtplot into a.jpg or. jpeg or .bitmap or any format and save it to the same directory which i can afterwards use to analyse few things.

    Can anyone please suggest me the right path to do the needful.

    Thanks in Advance

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    a) Use QwtPlot:rint(QPaintDevice&, ...);
    b) Use QPixmap::grabWidget

    I always recommend a) because the plot is rendered to the geometry of your target and with SVG or PDF you can have a scalable vector graphics format. F.e. you can zoom in a PDF viewer later ( limited by the fact, that Qwt still uses integers, because of Qt3 compatibility ).
    The bode example shows how to do it.

    With b) you get a screenshot of your window.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    Krish (19th March 2008)

  4. #3
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    Hello! Uwe,
    Thanks very much for informing me that. I got the required result with step a).
    But i also want to save the screenshot of my widget, for which i tried step b) but not working
    Here is what i tried: -

    QPixmap screen;
    screen.grabWidget(this);
    screen.save("screenshot","JPG",-1);

    Can you please suggest where am i going wrong?

    Thanks in advance.
    Last edited by Krish; 19th March 2008 at 10:38.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    grabWidget() is a static method.

  6. The following user says thank you to wysota for this useful post:

    Krish (19th March 2008)

  7. #5
    Join Date
    Jan 2006
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    Quote Originally Posted by Krish View Post
    Hello! Uwe,
    Thanks very much for informing me that. I got the required result with step a).
    But i also want to save the screenshot of my widget, for which i tried step b) but not working
    Here is what i tried: -

    QPixmap screen;
    screen.grabWidget(this);
    screen.save("screenshot","JPG",-1);

    Can you please suggest where am i going wrong?

    Thanks in advance.
    I think you need to do this:
    QPixmap screen;
    screen = QPixmap::grabWidget(this);
    screen.save("screenshot","JPG",-1);

    Thadeu

  8. #6
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    Hey! Thanks Thadeu for replying, but i have already solved the problem.

    Best Regards.

  9. #7
    Join Date
    Sep 2008
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    hello everyone

    i had to reopen this thread i am sorry for not understanding it.I have multiple Qt windows and want to save each of them in png or bmp and not as a screenshot,but with a name.
    i am using Qt 3.1 in redhat9.0 n rtlinux 3.1.
    As suggested by Uwe
    Qt Code:
    1. Qwtplot::print(QPaintdevice &paintdevice,const Qwtplotprintfilter &pfilter =Qwtplotprintfilter())
    To copy to clipboard, switch view to plain text mode 
    how is this done ? does it mean derive QPaintdevice object from print() and get the geometry of the window.what does Qwtplotprintfilter does.Is this function helpful for print.

    how to save?.
    hello krish how did u solve the problem,i am very new to qwt.

    regards
    Amrita
    Last edited by wysota; 30th December 2008 at 09:57. Reason: missing [code] tags

  10. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    QPaintDevice is a base class for object you can "draw on", such as QWidget, QPrinter, QImage or QPixmap. Therefore what you need to do is pass a pointer to the image object you want to render the widget on and then save the image to disk.
    Last edited by wysota; 30th December 2008 at 10:20.

  11. #9
    Join Date
    Sep 2008
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    hi

    thanks wysota for writing simply.Uwe comments were also helpful. i could figure it out
    Qpixmap screen;
    QwtPlotPrintFilter filter;

    apply options;
    screen=QPixmap::grabWidget(this);
    screen.fill(Qt::white);
    _plot->print(screen,filter);
    screen.save(filename,"PNG",-1);

    this sequence got me a window saved with all scales intact.

    regards
    Amrita

  12. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    QPixmap screen;
    screen=QPixmap::grabWidget(this);
    If you want a screenshot you already have it in screen and you have to remove your following code, that overwrites your screenshot. If not the code above is pointless and you better initialize your pixmap this way:

    Qt Code:
    1. QPixmap screen(800, 600); // or any other size you like.
    To copy to clipboard, switch view to plain text mode 

    Uwe

  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!

    If you use grabWidget, there is no point in calling print. Do one or the other, otherwise you'll get a huge overhead. Instead of grabWidget I suggest you create a pixmap with appropriate dimensions in the first place.
    Qt Code:
    1. QPixmap screen(this->size()); // or better yet _plot->size() if available
    2. _plot->print(screen, filter);
    To copy to clipboard, switch view to plain text mode 

  14. #12
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can i save or convert qwtplot into say .jpg or .jpeg, or ....!


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.