Allow to use icon.source: "qrc:/testicon.png" in buttons.
QIcon only seems to accept :/foo.png, not qrc:/foo.png, whereas I can't pass :/foo.png from QML and need to use qrc:/foo.png and hack away the prefix.
No Linters Available |
No Unit Test Coverage |
Buildable 26477 | |
Build 26495: arc lint + arc unit |
Fixing QIcon would make sense but I'd say getting this in is not the worst thing either.
plugin/kquickstyleitem.cpp | ||
---|---|---|
218 ↗ | (On Diff #78197) | should it also catch the ":/foo" case? |
I don't think it's QIcon's fault to be honest. The pattern used in several places of (icon.name || icon.source) doesn't help, it makes the lower layer loose the information of an icon specified by name (thus going through theme loading) or by URL (thus going through direct loading). Due to that the lower layer ends up having code trying to guess in which situation it is.
plugin/kquickstyleitem.cpp | ||
---|---|---|
182 | Note that this construct is duplicated three times in that file. It really calls for having a findIcon like that: QIcon KQuickStyleItem::findIcon(const QVariant &iconProp) const { if (iconProp.canConvert<QIcon>()) { return iconProp.value<QIcon>(); } else if (iconProp.canConvert<QString>()) { const auto iconId = iconProp.toString(); if (iconId.startsWith(QLatin1Char('/')) || iconId.startsWith(QStringLiteral(":/"))) { return QIcon(iconId); } else if (iconId.startsWith(QStringLiteral("file:"))) { return QIcon(QUrl(iconId).toLocalFile()); } else if (iconId.startsWith(QStringLiteral("qrc:"))) { return QIcon(QLatin1Char(':') + QUrl(iconId).path()); } else { return m_theme->iconFromTheme(iconId, m_properties[QStringLiteral("iconColor")].value<QColor>()); } } else { return QIcon(); } } And then using it for setting opt->icon and opt->currentIcon (combobox case). Yes, I did that locally and that definitely helped. |
Abandoning in favor of https://invent.kde.org/frameworks/qqc2-desktop-style/-/merge_requests/35