Results 1 to 8 of 8

Thread: Embedding Qwt plot High Resolution

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

    Default Embedding Qwt plot High Resolution

    I have the following problem.
    If I print a plot, for example its pdf version, the resolution is high and acceptable.
    Now, I would like to embed the plot in a TextDocument and print the document with the plots rendered as in the pdf file.
    I tried to grab the widget containing the plot, inserting the image inside the document and thenprint out. But, as I expected, the quality of the plot is very low.
    There is a way to solve this problem?
    G

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

    Default Re: Embedding Qwt plot High Resolution

    Use QwtPlot::print - it renders to any kind of paint device. I recommend to use a QSvgGenerator (= vector graphics ) but you can also render to a QImage and save it in the format you like.

    When you render to a QImage don't forget:

    QImage image(...);
    image.fill(Qt::transparent); // or whatever background you want to have
    ...

    HTH,
    Uwe

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

    Default Re: Embedding Qwt plot High Resolution

    Uwe,
    I would like to use SVG but as I stated in another post, SVG does not handle very well the borders of my plots...

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

    Default Re: Embedding Qwt plot High Resolution

    Anyway, the way suggested by UWE produces a plot without axis.
    I used the following code:


    Qt Code:
    1. ...
    2. image = new QImage(400,600,QImage::Format_RGB32);
    3. ....
    4. QImage* MyPlot::getImage()
    5.  
    6. {
    7.  
    8. QSvgGenerator generator;
    9. int options = QwtPlotPrintFilter::PrintAll;
    10. options |= ~QwtPlotPrintFilter::PrintBackground;
    11. options |= QwtPlotPrintFilter::PrintFrameWithScales;
    12. filter.setOptions(options);
    13.  
    14. image->fill(Qt::white);
    15.  
    16. return image;
    17. }
    To copy to clipboard, switch view to plain text mode 
    As you can see, the image is in poor quality too.
    Attached Files Attached Files

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

    Default Re: Embedding Qwt plot High Resolution

    a) Qwt 5.2 clips the curves at the canvas borders for SVG.
    b) The posted code snippet is nonsense - but if it has something to do with the application you are using for rendering your image: 400x600 is a very low resolution.

    If you want an high resolution image you need to create a much larger QImage ( the size of the image is the resolution !). But it's obvious that using Qwt 5.2 with SVG ( or PDF - what is also a vector graphics format ) is much better than using any raster graphics format that produces huge output.

    Uwe

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

    Default Re: Embedding Qwt plot High Resolution

    I found a solution and it works good.
    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    2. ...
    3. int pw = printer.pageRect().width();
    4. int ph =printer.pageRect().height();
    5.  
    6. p.begin(&printer);
    7.  
    8. p.save();
    9. m_document->adjustSize();
    10. QTransform tra;
    11. tra.scale(11,11);
    12. p.setTransform(tra);
    13.  
    14. m_document->drawContents(&p,printer.paperRect());
    15.  
    16.  
    17. p.restore();
    18. QRect rec(-10,0,pw-10,0.4*ph);
    19. p.translate(0,0.65*ph);
    20. solarDiagram->print(&p,rec,filter);
    21. p.end();
    To copy to clipboard, switch view to plain text mode 
    This is good for A4 paper. The plot is rendered as a vector graphic and I like it.
    But I would scale the painter automatically. The value "11" is taken from a trial-and-correct approach.
    Moreover, I noticed that if I translate the painter, Qwtplot does not print the title of the plot anymore. If I do not translate the painter everything is printerd.Why?

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

    Default Re: Embedding Qwt plot High Resolution

    Probably a bug in Qwt, that doesn't handle the translation. Try to translate the target rectangle instead of the painter.

    Uwe

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

    Default Re: Embedding Qwt plot High Resolution

    How? May you a bit more detailed....
    What do you mean for target rect?
    G

Similar Threads

  1. Replies: 4
    Last Post: 10th October 2009, 17:59
  2. legend inside qwt plot
    By kaustav98255 in forum Qwt
    Replies: 5
    Last Post: 11th February 2009, 20:39
  3. Detecting changes in the qwt plot axis
    By mrcolin in forum Qwt
    Replies: 2
    Last Post: 27th January 2009, 12:53
  4. export and printing qwt plot
    By giusepped in forum Qwt
    Replies: 6
    Last Post: 17th December 2008, 07:04
  5. Qwt plot problem on compile
    By sincnarf in forum Qwt
    Replies: 2
    Last Post: 14th October 2007, 11:36

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.