Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
SvgIcon: add new class to work around issues with SVG QIcons in Plasma/KStatusNotifierItem #3359
This commit adds new class SvgIcon which allows you to create a QPixmap-backed QIcon
We need this to fix #3124.
Basically, SVG-backed QIcons returns an empty list for QIcon::availableSizes().
However: Plasma/KStatusNotifierItem currently expects QIcon::availableSizes()
This commit works around this by constructing a QIcon backed by pixmaps, such that
This is implemented via the static method, SvgIcon::addSvgPixmapsToIcon(), which renders
mkrautz left a comment
I am not convinced this is a good workaround.
If we DO need a workaround for some versions of Qt, I'd be more inclined to refactor the code you removed from MainWindow.cpp:
to create QIcons that include rasterized PNGs for various sizes.
IMHO, the correct fix for this would be to define a new loading function/class, like:
In my mind, your current code relies on QPixmap::load rendering a reasonably sized QPixmap from the SVG. We don't know how it determines what size to use. My guess would be that it would use the baseline size specified in the SVG itself. However, that's not documented. Creating a QPixmap from an SVG could produce a 4096x4096 pixmap, or an 8k one. Who knows?
As such, I'd prefer to be explicit. and use a routine tuned for icons like I suggest above.