Results 1 to 2 of 2

Thread: Problem with saving QChartView as vector image file

  1. #1
    Join Date
    Apr 2021

    Default Problem with saving QChartView as vector image file

    I using the QChartView to plot two-line series.Capture.jpg

    To save this graph, I am using the following code. Although it works fine when I save it as a .png file. However, when I try to save it as .svg format it doesn't do anything.

    Can anybody tell me what might be the issue?

    Qt Code:
    1. QString path = QFileDialog::getSaveFileName(this, tr("Save as image"), "", tr("Image (*.svg *.png);;All Files (*.*);;"));
    2. if (path.isEmpty()) {
    3. qDebug() << "USER DID NOT SELECT the PATH!!!!!";
    4. return;
    5. }
    6. QImage img((chartView->size()), QImage::Format_ARGB32);
    7. QPainter painter;
    8. painter.begin(&img);
    9. chartView->render(&painter);
    10. painter.setRenderHint(QPainter::Antialiasing);
    11. painter.end();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 851 Times in 838 Posts
    Qt products

    Default Re: Problem with saving QChartView as vector image file

    Can anybody tell me what might be the issue?
    Have you included SVG support in your project? It isn't built-in like PNG.

    The procedure for rendering SVG is not the same as rendering a pixmap image. Look at QSvgRenderer and QSvgGenerator and the SVG Generator example.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 5
    Last Post: 6th December 2016, 17:11
  2. Image Saving Problem
    By WarGamer in forum Qt Programming
    Replies: 5
    Last Post: 30th July 2012, 20:35
  3. Replies: 2
    Last Post: 21st August 2009, 23:09
  4. Problem saving JPG image
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 31st July 2009, 15:38
  5. Saving pure plot data to image file
    By Debilski in forum Qwt
    Replies: 4
    Last Post: 7th April 2009, 17:02


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.