Results 1 to 2 of 2

Thread: QSvgWidget Question

  1. #1
    Join Date
    Apr 2009
    Location
    Ottawa, Canada
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSvgWidget Question

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSvgWidget Question

    EDIT: Whole of grub. Forget my answer. was too late... Sorry

    EDIT 2: New solution may it works:
    Qt Code:
    1. QByteArray ba(mySvgString);
    2. mySvgWidget->load(ba);
    To copy to clipboard, switch view to plain text mode 
    or maybe use toLocal8Bit() instead of toAscii().
    Last edited by Lykurg; 1st May 2009 at 22:07.

Similar Threads

  1. licensing question
    By tommy in forum Installation and Deployment
    Replies: 4
    Last Post: 14th April 2010, 11:54
  2. Plugin implementation question
    By JPNaude in forum Qt Programming
    Replies: 12
    Last Post: 27th August 2008, 20:24
  3. Useless but curious compiler warning question
    By Raccoon29 in forum General Programming
    Replies: 4
    Last Post: 30th July 2008, 20:46
  4. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.