Including a custom icon for desktop widget/plasmoid?

Hello!

I’m wondering if it’s possible to include a custom SVG icon for a desktop widget that I’m developing.
Neither icon property in the documentation seems to mention anything about this, and instead require you use a system icon.

For my personal use, I solved this by just copying the desired SVG into my own local icons directory, but ideally I’d like to have it contained within the package folder so it’s easier for others to install the widget.
I also tried setting the “Icon” field in metadata.json to “./widget_icon.svg" and "widget_icon.svg"(with the SVG file named widget_icon.svg and in the same directory as metadata.json), but neither seemed to work.

hi, welcome.

never made a widget, but a quick look at the docs suggest you just call out the icon location in your contents/ui/main.qml file.

where you put the icon file is up to you… for my service menus that use custom icons, i keep them in folder with the service menu ~/.local/share/kio/servicemenus/, you could likely just put the .svg in at the same level as the .json

but it seems you need to specify the full path, shortcuts like~, . or $HOME don’t seem to work which you will need to take care of with an install.sh script

Setting a custom path in the widget metadata.json is currently not possible, here is the feature request for that: https://bugs.kde.org/show_bug.cgi?id=509896

So while you can ship a custom icon and display it when the widget is added to the panel/desktop (using Kirigami.Icon), other places like the widget explorer or the widget about page need an icon that is on the icon theme.

Is running post install scripts possible outside global themes? I don’t think it is but can’t find any documentation on install scripts of any kind of plasma add-ons

i have a dolphin service menu on the kde store and it has an install script

install.sh seems to be run automatically if it exists in the source package upload.

don’t know if works the same for widgets, but it’s worth a shot.

So how do “Binary clock”, “Application Launcher” address this. Does kde ship with them statically? ( i assume ).

Hmm that’s interesting, will take a look at the code to see how the widget explorer is showing that

Turns out it is actually possible to but it seems I can’t read, even the issue I linked mentions that the icon needs to be placed inside the contents directory:

So for example here:

package/
├── contents
│   ├── config
│   │   ├── config.qml
│   │   └── main.xml
│   ├── icon.png
│   ├── icons
│   │   └── icon.svg
│   └── ui
│       └── main.qml
└── metadata.json

Icon can be "Icon": "/icons/icon.svg" or "Icon": "/icon.png" and both work, the issue i linked is only about the AboutPlugin which will not load this custom icon.

2 Likes

What changes should be made to the metadata.json? Could you also link the thread.