diff --git a/src/duckstation-qt/svgwidget.cpp b/src/duckstation-qt/svgwidget.cpp index 01f021a62..e93a0b49d 100644 --- a/src/duckstation-qt/svgwidget.cpp +++ b/src/duckstation-qt/svgwidget.cpp @@ -88,6 +88,11 @@ void SVGWidget::destroyDocument() m_svg_data.deallocate(); } +QColor SVGWidget::effectiveColor() const +{ + return m_color.isValid() ? m_color : palette().color(QPalette::WindowText); +} + void SVGWidget::rasterize() { m_pixmap = {}; @@ -126,7 +131,13 @@ void SVGWidget::rasterize() // Use white as currentColor so the SVG's own colours are preserved. // Swap in a palette colour here if tinting is ever desired. - const plutovg_color_t current_color = {.r = 1.0f, .g = 1.0f, .b = 1.0f, .a = 1.0f}; + const QColor color = effectiveColor(); + const plutovg_color_t current_color = { + .r = static_cast(color.redF()), + .g = static_cast(color.greenF()), + .b = static_cast(color.blueF()), + .a = static_cast(color.alphaF()), + }; plutovg_surface_t* const surface = plutosvg_document_render_to_surface(m_document, nullptr, render_w, render_h, ¤t_color, nullptr, nullptr); @@ -173,7 +184,9 @@ void SVGWidget::changeEvent(QEvent* event) QWidget::changeEvent(event); // Re-rasterize when the screen changes (e.g. window moved to a display with a different DPR). - if (event->type() == QEvent::DevicePixelRatioChange || event->type() == QEvent::ScreenChangeInternal) + // Or when the theme/current colour changes. + const QEvent::Type type = event->type(); + if (type == QEvent::DevicePixelRatioChange || type == QEvent::ScreenChangeInternal || type == QEvent::PaletteChange) { m_last_raster_size = {}; // force re-render rasterize(); diff --git a/src/duckstation-qt/svgwidget.h b/src/duckstation-qt/svgwidget.h index 33ae68baf..de714251c 100644 --- a/src/duckstation-qt/svgwidget.h +++ b/src/duckstation-qt/svgwidget.h @@ -50,6 +50,9 @@ protected: void changeEvent(QEvent* event) override; private: + // Effective value of currentColor for rasterization, taking into account the widget's palette and m_color. + QColor effectiveColor() const; + /// (Re)render m_document at the current widget size + DPR and store the result in m_pixmap. void rasterize();