Saving the contents of a Qwt widget as SVG



  • Hello,
    I am trying to build a function to my program that will save the image of a Qwt plot as an SVG file. This is the code that does the conversion:

    QSvgGenerator averageChargesGraphGenerator;
    QString averageChargesFileName;
    averageChargesFileName.append(directoryName).append(forwardSlash ? QString("/") : QString("\\")).append(QString("averagechargetestvoltagegraph.svg"));
    averageChargesGraphGenerator.setFileName(averageChargesFileName);
    
    averageChargesGraphGenerator.setSize(ui.averageChargeTestVoltageWidget->size());
    averageChargesGraphGenerator.setViewBox(ui.averageChargeTestVoltageWidget->rect());
    
    QPainter averageChargesGraphPainter(&averageChargesGraphGenerator);
    ui.averageChargeTestVoltageWidget->render(&averageChargesGraphPainter);
    	
    averageChargesGraphPainter.setPen(pen);
    averageChargesGraphPainter.drawLine(QPoint(0, 0), QPoint(0, 500));
    averageChargesGraphPainter.drawLine(QPoint(0, 500), QPoint(500, 500));
    averageChargesGraphPainter.drawLine(QPoint(500, 500), QPoint(500, 0));
    averageChargesGraphPainter.drawLine(QPoint(500, 0), QPoint(0, 0));
    
    1. I create a QSvgGenerator object. I set the file name. Then I set the size to the size of the widget. I set the viewBox to the rect() of the widget.
    2. I create a QPainter object, passing a pointer to the QSvgGenerator object in the constructor.
    3. I call the render() method of the Qwt widget, passing it a pointer to the QPainter object.
    4. Then I draw some lines to draw an enclosing box around the image.

    So, I did everything according to the online guide. However, it seems that the contents of the plot (such as lines, points etc.) have not been saved in vector graphic format. Instead, they have been saved like a PNG image that has been embedded into the SVG file. This is from the XML source of the generated SVG file:

    <image x="0" y="0" width="480" height="445" preserveAspectRatio="none" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeAAAAG9CAIAAABCpjLrAAAACXBIWXMAABJ0AAASdAHeZh94AAAJKUlEQVR4nO3dXXLaSBhAUZzyPtladso8uGoqsbEjQFLfls55m6k4pUDr8ukPv/3+/fsCQMz1ev01ehsA+Ox6vV4ul/c//wOADhM0QJRAA0S9j94AOIK3t8f+/O22zXZwLAINl8uPhRVT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MAwP0/ZJmiAKBM0sJUDPMs3lkADm5juqZBXbPSPFWhgQzs8y3fgTwKBBtbxdChf/L2rY226MQINHEGq2msR6FO7O7kccqGzqVXWzJK/5MBnM+5ym91JqTD0maDP62ujzzaeMIqVtpBA85nzHmzndlPnBwg0sCsf9stFA+0zdoi7e473AkZxkRAgKjdBO/wB+GCCBojKTdA0ORMN+xNo/sF9UdScZ0EKNP/mwgARZxsXBBqYyanGBRcJAaJM0MC5TPRlBiZo4CyaFf6BCRo4kbm+xFGgAaLnPQQa4L7hw7VAA6f23Zg8vM4XgQa4a/j5jYu7OACyBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaIEGiBKoAGiBBogSqABogQaIEqgAaLeR2/AOby9jd6Cl91uo7fgewd4edey+tu052tbXmOD/B1oC53vWBtTmPptmnrjV/THB5VTHABRAg0QJdAAUQINEOUujr1MfYV6oqs3U7/Oz9n63dn0JZ1oaY3wd6BPuLhZwsIom/rdmXrjt+cUB0CUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QJRAA0QJNECUQANECTRAlEADRAk0QNSvy+VyvV5HbwYAn73dbrfR2wDAHf8BvpgJm7p+1C0AAAAASUVORK5CYII=" />
    

    Notice that at the beginning of the xlink:href field, it says "data:image/png". One interesting thing is that only the contents of the plot have been saved like this. The legends, axes, numerations etc. of the graph have been saved in vector graphic format.
    So what did I do wrong and what do I need to change to save the contents of the graph in the vector graphics format? Thanks in advance.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.