PDA

View Full Version : QSvgWidget Question



craigdillabaugh
1st May 2009, 22:15
Hi I wanted to create some custom buttons and thought it would be easy to use a simple SVG graphic (rather than do something with QPainter, because I like the way the SVG graphics look).

I want to generate the SVG graphic in my code and then load it to the widget using QSvgWidget::load(). So I created a function to generate a QString that represented the SVG file, but every time I attempted to load those like:


mySvgWidget->load(mySvgString.toAscii()) //toAscii returns QByteArray

load returns an error (I can avoid the error if I don't use any quotes (") in my string, but you can't do much without those). Also, the SVG code inside the string if written to disk and loaded as a file worked fine.

So, I tried using a QXmlStreamWriter to write the SVG graphic to a QByteArray, and this didn't work either. However, if I use QXmlStreamWriter to write the exact same XML code to a file and then used:


mySvgWidget->load("fileFromXMLWriter.svg")

Everything works fine. This is a reasonable workaround, but I don't know why I can just write my SVG to a QByteArray and load that?

Thanks for any help.
Craig

Lykurg
1st May 2009, 23:01
EDIT: Whole of grub. Forget my answer. was too late... Sorry

EDIT 2: New solution may it works:

QByteArray ba(mySvgString);
mySvgWidget->load(ba); or maybe use toLocal8Bit() instead of toAscii().