Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.14.2
-
None
-
Arch Linux 5.6.10-arch1-1
Qt 5.14.2
Description
Posted on StackOverflow: https://stackoverflow.com/questions/61702520/qml-qt-labs-platform-menuitems-icon/61703709#61703709
See my solution below the question.
There's a plugin called Qt.labs.platform. Among other things, it provides tray icon with a menu. That menu has a list of MenuItem. Any menu item may have an icon, which would be displayed on the left side of item's text.
There's two ways of setting the icon, none of which work for me:
1) Version 1.0 defined iconSource and iconName properties.
Silently does not work, just shows no icon.
2) Revision 1.1 (declared as Q_REVISION(1)) introduces icon.name, icon.source and icon.mask "sub-properties" (not sure what's the right name for it?)
Fails QML engine with a message:
"MenuItem.icon" is not available in Qt.labs.platform 1.1.
I tried both import Qt.labs.platform 1.1 and 1.0.
Am I missing something in the mechanics of QML revisions or this is a bug in Qt?
A MenuItem is declared in qquickplatformmenuitem_p.h and defined in qquickplatformmenuitem.cpp files.
I'm using ArchLinux, KDE/Plasma. Some other apps (like electron-based) do have their icons in menu showing properly.
So, I dig into source code, and found out that it was indeed a bug. Someone forgot to register QQuickPlatformMenuItem class for the revision 1. It should've been done similar to QQuickPlatformSystemTrayIcon like this:
qmlRegisterType<QQuickPlatformSystemTrayIcon>(uri, 1, 0, "SystemTrayIcon"); qmlRegisterType<QQuickPlatformSystemTrayIcon, 1>(uri, 1, 1, "SystemTrayIcon");
And also "plugins.qmltypes" should re-generated after that.
I managed to build the whole qtquickcontrols2 repository because I haven't found any easier way to build only qtlabsplatformplugin target. So anyway, Qt stopped complaining on the "non-available" MenuItem.icon.
But that's only half problem solved, because I still don't see any icon in the tray icon's menu item. I'm attaching the patch for imports right away.
UPD As explained in a comment below, `icon.name` doesn't work. `icon.source` works, but only without name being defined. Named icon loads, but for some reason can not be displayed. Tested on both png and svg.