Use SVG Icons in wxWidgets C++ Applications

Render SVG icons in wxWidgets with wxBitmapBundle

This guide shows how to use SVG icons in wxWidgets C++ apps, starting from clean SVGs exported with Axialis IconVectors. You will import SVG from a wxString or from an external file, convert to wxBitmap, and draw on screen.

What is wxWidgets? How SVG is handled

Export a clean SVG from IconVectors

  1. Open or create your icon:
    • File → Open… (Ctrl+O) or New Icon (Ctrl+N).
    • Prefer a simple, single‑color shape with a clean viewBox (e.g., 0 0 24 24).
    Preparing an SVG icon in IconVectors
    Export a minified SVG via File → Export → Export Minified (Shift+Ctrl+M).

Option A — Inline SVG (wxString) ➜ wxBitmap with wxBitmapBundle::FromSVG

Use wxBitmapBundle::FromSVG() to create a scalable bundle from an SVG string, then request a wxBitmap for your target size and draw it.

#include <wx/wx.h>

static const char kSvg[] = R"SVG(
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" 
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" 
stroke-miterlimit="10" d="M14.8 3.4l1.9 2.3c.2 .2 .5 .4 .8 .4H20c1.1 0 2 .9 2 
2v10c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V8c0-1.1 .9-2 2-2h2.5c.3 0 .6-.1 .8-.4l1.9-2.3
c.2-.2 .5-.4 .8-.4h4.1C14.3 3 14.6 3.1 14.8 3.4zM8.5 12.5c0 1.9 1.6 3.5 3.5 3.5
s3.5-1.6 3.5-3.5s-1.6-3.5-3.5-3.5S8.5 10.6 8.5 12.5z"/></svg>
)SVG";

class MyApp : public wxApp {
public:
  bool OnInit() override {
    auto* frame = new wxFrame(nullptr, wxID_ANY, "SVG in wxWidgets (FromSVG)", wxDefaultPosition, wxSize(260,180));

    // Build a scalable bundle from an in-memory SVG
    wxBitmapBundle bundle = wxBitmapBundle::FromSVG(kSvg, wxSize(24,24));
    wxBitmap bmp = bundle.GetBitmapFor(wxSize(24,24)); // request target size

    frame->Bind(wxEVT_PAINT, [frame, bmp](wxPaintEvent&){
      wxPaintDC dc(frame);
      dc.DrawBitmap(bmp, 40, 40, /*useMask=*/true);
    });

    frame->Show();
    return true;
  }
};
wxIMPLEMENT_APP(MyApp);

Tip: For HiDPI, compute the target size with frame->FromDIP(wxSize(24,24)) before calling GetBitmapFor().

Option B — External file ➜ wxBitmap with wxBitmapBundle::FromSVGFile

Load an SVG from disk (e.g., icons/check.svg packaged with your app), get a wxBitmap, and draw it.

#include <wx/wx.h>

class MyApp : public wxApp {
public:
  bool OnInit() override {
    auto* frame = new wxFrame(nullptr, wxID_ANY, "SVG in wxWidgets (FromSVGFile)", wxDefaultPosition, wxSize(260,180));

    wxString path = wxT("icons/check.svg");
    wxBitmapBundle bundle = wxBitmapBundle::FromSVGFile(path, wxSize(24,24));
    wxBitmap bmp = bundle.GetBitmapFor(wxSize(24,24));

    frame->Bind(wxEVT_PAINT, [frame, bmp](wxPaintEvent&){
      wxPaintDC dc(frame);
      dc.DrawBitmap(bmp, 40, 40, /*useMask=*/true);
    });

    frame->Show();
    return true;
  }
};
wxIMPLEMENT_APP(MyApp);

Notes & troubleshooting

Start Making SVG Icons Today with IconVectors

Download the fully-functional 30‑Day Free Trial and unlock your icon design workflow.

Version 1.10 - September 17, 2025