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:

Qt Code:
  1. mySvgWidget->load(mySvgString.toAscii()) //toAscii returns QByteArray
To copy to clipboard, switch view to plain text mode 

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:

Qt Code:
  1. mySvgWidget->load("fileFromXMLWriter.svg")
To copy to clipboard, switch view to plain text mode 

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