PDA

View Full Version : SVG Generation Problem



Jime22
30th April 2008, 23:49
I am new to QT and C++ I am working on some basic code snippets to try learn the API. My latest stumbling block involves SVG, QGraphicsScene and QSvgGenerator. My problem is that when I go to generate an SVG file from a QGraphicsScene, my SVG Graphics is converted to a pixal image(png). The Text stays as scalable text. My SVG File is an elipse w a square inside of it(very simple).

the Svg file that I read in is below. ...just wanted to include it to show it was not a pixal file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Creator: CorelDRAW -->
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="1.37686in" height="1.32638in" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd" clip-rule="evenodd"
viewBox="0 0 342.62 330.058"
xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="Layer_x0020_1">
<metadata id="CorelCorpID_0Corel-Layer"/>
<ellipse fill="none" stroke="red" stroke-width="3.45537" cx="171.31" cy="165.029" rx="169.582" ry="163.301"/>
<rect fill="none" stroke="red" stroke-width="3.45537" x="31.0386" y="77.0978" width="276.355" height="188.424"/>
</g>
</svg>



I have a GraphicsScene that is 1200x1200.
I add my svg item to the scene with the following code.
I also add a text item.

QGraphicsSvgItem *mysvg = new QGraphicsSvgItem("/home/jim/testj1.svg");
scene->addItem(mysvg);
mysvg->setZValue(2);
mysvg->setPos(30,20);


QGraphicsTextItem *Myitem;
Myitem = scene->addText("Hello, This is the time to start");
Myitem->setPos(20,200);
Myitem->setZValue(2);



I do my SVG Generating w the following code

QSize mysize(200,200);
QSvgGenerator *gen = new QSvgGenerator();
gen->setResolution(200);

gen->setSize(mysize);
gen->setFileName("/home/jim/j1.svg");
QPainter *svgPainter = new QPainter(gen);
svgPainter->scale(10,10);

scene->render(svgPainter);
svgPainter->end();

Just to recap...I can read an svg file and place it on a QGraphicsScene, I can save the QGraphicsScene to an SVG file, but the svg file that was placed on the QGraphicsScene is converted to a png image and placed into the new svg file.
any help on how to get everything to be saved as scalable vectors would be appreciated.
:confused: