How to load an SVG icon in QIcon with currentColor support?
-
I'm trying to load an SVG icon into QIcon while supporting currentColor. The SVG file contains elements using fill="currentColor", and I want it to take the color from the color property of the parent widget (e.g., QPushButton).
Here’s my current approach:
QIcon icon(":/icons/my_icon.svg"); button->setIcon(icon); button->setStyleSheet("QPushButton { color: red; }");
However, the icon remains black instead of inheriting the button's text color.
Is there a built-in method in Qt to support this behavior, or do I have to manually render the SVG with the correct color before setting it in QIcon?
-
QtSvg does not support this yet. There is also a bug report about this.
You can modify the svg file on disk for example. -
It's unfortunate that QtSvg doesn't support currentColor yet. Do you happen to have a link to the bug report? I'd like to track its progress.
For now, modifying the SVG file on disk could be an option, but I was hoping for a more dynamic solution.Thanks!