fix: Re-set SVG renderer aspect ratio after load (#6334)

The `QSvgRenderer::setAspectRatioMode` function only sets the aspect
ratio setting for the currently loaded SVG document.
https://github.com/qt/qtsvg/blob/29c3b512d9ca25941b18f7ee52ce8b80f003f3b4/src/svg/qsvgrenderer.cpp#L311-L320

When the theme changes, or we otherwise call load, this does not retain
our aspect ratio settings.
https://github.com/qt/qtsvg/blob/29c3b512d9ca25941b18f7ee52ce8b80f003f3b4/src/svg/qsvgrenderer.cpp#L412-L432

This means we need to ensure we re-set the SVG renderer's aspect ratio
after calling load.
This commit is contained in:
pajlada
2025-07-18 22:42:26 +02:00
committed by GitHub
parent a691bb4c51
commit a8e8d61099
3 changed files with 11 additions and 3 deletions
+8 -2
View File
@@ -19,7 +19,7 @@ SvgButton::SvgButton(Src source, BaseWidget *parent, QSize padding)
void SvgButton::setSource(Src source)
{
this->source_ = std::move(source);
this->svg_->load(this->currentSvgPath());
this->loadSource();
this->invalidateContent();
}
@@ -48,7 +48,7 @@ void SvgButton::themeChangedEvent()
{
return;
}
this->svg_->load(this->currentSvgPath());
this->loadSource();
this->invalidateContent();
}
@@ -98,4 +98,10 @@ QString SvgButton::currentSvgPath() const
return this->source_.dark;
}
void SvgButton::loadSource()
{
this->svg_->load(this->currentSvgPath());
this->svg_->setAspectRatioMode(Qt::KeepAspectRatio);
}
} // namespace chatterino
+2
View File
@@ -72,6 +72,8 @@ protected:
private:
[[nodiscard]] QString currentSvgPath() const;
void loadSource();
Src source_;
QSvgRenderer *svg_;
QSize padding_;