Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
6.9.0
-
None
Description
Testcase:
QIcon icon;
icon.addFile("file1.svg", {}, QIcon::Selected, QIcon::On);
file1.svg gets actually added for the Normal/Off states , not for the specified one(s). Similarly,
QIcon icon; icon.addFile("file1.svg", {}, QIcon::Normal, QIcon::On); icon.addFile("file2.svg", {}, QIcon::Normal, QIcon::Off);
will result in file2.svg provided when asked for a pixmap in Normal/On. This is for the same reason – file1.svg got actually added as Normal/Off and the second addFile "overwrote" the first one.
I've investigated the issue a bit:
- QIcon::addFile calls iconEngineFromSuffix(fileName, suffix); here https://codebrowser.dev/qt6/qtbase/src/gui/image/qicon.cpp.html#1169
- iconEngineFromSuffix checks if any image plugin can load the file, it will find QSvgIconPlugin and call create(fileName) on it here https://codebrowser.dev/qt6/qtbase/src/gui/image/qicon.cpp.html#1118
- *QSvgIconPlugin::create outright ignores whatever mode one passed to addFile*, and hardcodes Normal/Off when loading the SVG here https://codebrowser.dev/qt6/qtsvg/src/plugins/iconengines/svgiconengine/main.cpp.html#_ZN14QSvgIconPlugin6createERK7QString
Attachments
Issue Links
- duplicates
-
QTBUG-135483 [REG 6.7-> 6.8] Loading order affects QIcon state and mode when adding svg images
-
- Closed
-