0

There's a plugin called Qt.labs.platform. Among other things, it provides tray icon with a menu. That menu has a list of MenuItems. 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.

UPD Reported as a Qt bug.

ratijas
  • 704
  • 7
  • 14

1 Answers1

0

I don't know what exactly you are doing to achieve your goal, because there is no minimal reproducible example.

But take a look at here

import QtQuick 2.12
import QtQuick.Window 2.12
// import Qt.labs.platform 1.1
import QtQuick.Controls 2.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle {
        width: 200
        height: 200
        anchors.centerIn: parent

        MenuBar {
            id: menuBar

            Menu {
                id: firstMenu

                MenuItem {
                    icon.name: "download"
                    icon.source: "icons/cloud-down-icon.png"
                }

                MenuItem {
                    text: qsTr("Rewrap Paragraph")
                    onTriggered: rewrapParagraph()
                }
            }
        }
    }
}


Note: put your icon inside the icons folder in the project folder.

If you click on the menu then you should get a dropdown with two items, first one is just an icon without the text (you can include some text by yourself), second item is just a text.

cppiscute
  • 707
  • 2
  • 10
  • 33
  • I wonder how that even loads, because two different `MenuItem`s are defined in QtQuick.Controls 2 and Qt.labs.platform. You tried to run it? Anyway, as I wrote in topic: `Menu.icon` is not available in 1.1. I already managed to find out why is that (spoiler: someone forgot to re-register the class for 1.1). However, icons still do not work for on my Linux. – ratijas May 09 '20 at 21:47
  • 1
    yup you are right it's not available in Qt.labs.platform 1.1, but why not use QtQuick.Controls to achieve what you want? – cppiscute May 09 '20 at 22:07
  • I don't have arch linux to test. But i will try to see why it doesn't work there. – cppiscute May 09 '20 at 22:10
  • OK. To my amusement, it somehow runs. But it does not look like it is using Qt.labs.platform. It is basically equivalent to this: https://gist.github.com/ratijas/9ef914f8dbf57360dc888e0294658a2a – ratijas May 09 '20 at 22:10
  • > why not use QQC 1) because I want to use native menu; 2) because system tray icon. Second reason is un-dodgeable. – ratijas May 09 '20 at 22:12