I am working on an application that requires a server request for an SVG that is representative of a particular product configuration. This is my first time dealing with SVG and I am hung up on decoding the server response in such a way where the image can be displayed with a QSvgRenderer. Something like this
QByteArray panelData(QS.toStdString().c_str(), QS.length());
QSvgRenderer renderSVG(panelData);
QImage image(500, 200, QImage::Format_ARGB32);
QPainter painter(&image);
renderSVG.render(&painter);
I also thought about going the qpixmap on qlabel route like this.
QPixmap pix;
pix.fromImage(image);
ui->PixLabel->setPixmap(QPixmap::fromImage(image));
I have attempted using QTextdocument::toHtml as others have suggested but only end up trading one set of decoding problems for others. Do the qt libraries have a direct way of rendering the response below?
A server reply in part...
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg width="307px" height="625px" version="1.1" xmlns="http://www.w3.org/2000/svg"> <defs> <linearGradient id="P-mlvr" x1="0%" y1="0%" x2="0%" y2="100%"> <stop offset="0%" style="stop-color:#f0f0f0;stop-opacity:1;" /> <stop offset="0.0625" style="stop-color:#e0e0e0;stop-opacity:1;" /> <stop offset="100%" style="stop-color:#d0d0d0;stop-opacity:1;" /> </linearGradient> <linearGradient id="P-flvr" x1="0%" y1="100%" x2="0%" y2="0%"> <stop offset="0%" style="stop-color:#b0b0b0;stop-opacity:1;" /> <stop offset="0.0625" style="stop-color:#e0e0e0;stop-opacity:1;" /> <stop offset="75%" style="stop-color:#e0e0e0;stop-opacity:1;" /> <stop offset="100%" style="stop-color:#d0d0d0;stop-opacity:1;>
QS
your first code snippet seems legit: what's not working? – MatGQByteArray
containing the svg (<xml ...<svg...</svg>
part), save to file ex.test.svg
and open it with a svg viewer (ex. browser) to check if it's valid? – MatG.svg
extension and try open it with your browser first – Soheil Armin