Results 1 to 4 of 4

Thread: Save QwtPlot as an image

  1. #1
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    112
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Save QwtPlot as an image

    Is there a way to save a QwtPlot as an image, e.g. as a PNG file?

    Thanks
    Gib

    I should add that I'm using Qwt5.2.1. I see that qwt_plot_renderer is available in Qwt6, but not in Qwt5.

    Now I see (from Uwe's reply to an old question) that the Bode plot example shows how to do it.

    And now I see that this example creates a SVG image file, not exactly what I want. It uses QSvgGenerator, and there is nothing equivalent for other image formats.
    Last edited by gib; 21st May 2018 at 01:19.

  2. #2
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    112
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Save QwtPlot as an image

    In case anyone is interested, this is what I did:

    QImage img(512, 512, QImage::Format_ARGB32);
    QwtPlotPrintFilter pf;
    pf.setOptions(QwtPlotPrintFilter::PrintAll);
    bool use_painter = false;
    if (use_painter) {
    QPainter painter;
    painter.begin(&img);
    qpFACS->print(&painter,QRect(0, 0, 512, 512),pf);
    painter.end();
    } else {
    qpFACS->print(img,pf);
    }
    img.save(path);

    where qpFACS is a QwtPlot. Both methods work, producing the bare plot. I haven't found how to get the frame, axes, titles etc. If somebody can tell me what I need to do I'll be grateful.

    Gib

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,200
    Thanked 848 Times in 797 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save QwtPlot as an image

    IIRC all elements should be part of what is generated by QwtPlot:rint out of the box.
    But a migration from Qwt 5 to 6 is not that hard and before fiddling around with versions that are ~10 years old ...

    Uwe

  4. #4
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    112
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Save QwtPlot as an image

    I can't recall now why I was reluctant to migrate to Qwt 6, but I think that something I was doing was not going to work the same way, and since 5 was doing everything I needed I decided not to rock the boat.


    Added after 55 minutes:


    I've been experimenting with the Bode example, saving the plot to an image file with
    d_plot->print(img,pf)
    Interestingly, in the image the only things that appear outside of the actual plot area are the short yellow and cyan lines that appear next to 'Amplitude and 'Phase' at the bottom. Since the image background is black, I surmise that nothing else shows because all the rest (axis title, title, axis markings etc) are black. Apparently I need to change the background of the printed image to white (it is grey onscreen). I thought that this might do it:
    pf.color(Qt::GlobalColor::white,QwtPlotPrintFilter ::WidgetBackground);
    but it has no effect, and nor does the same with CanvasBackground, and nor does trying to change AxisTitle by the method.
    Maybe I am misunderstanding what pf.color() is supposed to do.
    Last edited by gib; 22nd May 2018 at 02:25.

Similar Threads

  1. Replies: 15
    Last Post: 24th July 2015, 23:33
  2. save image
    By lozdog in forum Newbie
    Replies: 1
    Last Post: 19th May 2014, 08:06
  3. Replies: 4
    Last Post: 30th May 2012, 00:37
  4. Qwt & save as image
    By giostau in forum Qwt
    Replies: 1
    Last Post: 8th February 2012, 15:41
  5. Replies: 11
    Last Post: 31st December 2008, 13:30

Tags for this Thread

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.