Use SVG Icons in wxWidgets C++ Applications

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
- Cross‑platform native GUI — Windows, macOS, and Linux using the platform’s native widgets for a natural look and feel.
- Open‑source and commercial‑friendly — uses the wxWidgets Library License; free for commercial apps.
- SVG in wxWidgets — modern versions provide
wxBitmapBundle
helpers:FromSVG()
for in‑memory SVG (string) andFromSVGFile()
for on‑disk SVG. Under the hood, a lightweight SVG rasterizer (NanoSVG) turns the vector into pixels at any size. - Pros — crisp icons at any DPI; one vector source replaces many PNG sizes; simple API to obtain a
wxBitmap
. - Cons — complex SVG filters/effects are out of scope; prefer simple paths, strokes, and flat fills for UI icons.
- Download — get wxWidgets from wxwidgets.org (source packages and links to package managers).
Export a clean SVG from IconVectors
- 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
).
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
- Requirements — use a recent wxWidgets (3.2+ recommended) with SVG support enabled. On some setups, SVG helpers depend on NanoSVG at build time.
- HiDPI — request bitmaps via
GetBitmapFor(frame->FromDIP(size))
so the rasterized size matches the monitor scale. - Keep SVG simple — prefer paths/fills/strokes; avoid advanced filters. Export minified SVG from IconVectors.
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