Search code examples
c++svgwxwidgets

How to add SVG to an application with wxWidgets?


I'm new to C++ and I want to replace a PNG image in the GUI of my application with a SVG in wxWidgets 3.2.2.1. The part of my XML/XRC file containing information about the image has the following structure:

    <object class="wxStaticBitmap" name="testfile_1">
        <size>100, 100</size>
        <bitmap>testimage.png</bitmap>
    </object>

When I change my code to

    <object class="wxSVGFileDC" name="testfile_1">
        <size>100, 100</size>
        <bitmap>testimage.svg</bitmap>
    </object>

and compile my application and start it however, I always get an uninitialized sizer item error.

It looks like the sizer doesn't recognize my SVG. What should I do with my code or elsewhere so that my application successfully starts with the SVG? Any help would be greatly appreciated.


Solution

  • I don't know why did you decide to use wxSVGFileDC, which is used for creating SVG files in your XRC (did ChatGPT advise this?), but if you look at XRC documentation you can easily see that it's not an allowed element there. And if you tried to validate your XRC file you would have also found out that it doesn't pass the validation.

    On the same XRC documentation page you can also read, in the "Bitmap" section that to use SVG in your XRC file you simply need to write

            <bitmap default_size="32,32">testimage.svg</bitmap>