Widget Properties
Plasmoid property group
As discussed in the main.qml
setup widget section, when you import org.kde.plasma.plasmoid 2.0
, the main Item
in your widget will have the Plasmoid
(with a capital) property group similar to when you import QtQuick.Layouts 1.0
. This Plasmoid
property group has properties from
AppletInterface
which inherits a few properties from PlasmaQuick::AppletQuickItem
.
plasmoid context property
You can reference a property from the Plasmoid.___
property group by the root Item { id: widget }
of the widget with widget.Plasmoid.___
. An easier method is to use the global context property plasmoid
(lowercase) which is dynamically defined at runtime when the property group is imported.
import QtQuick 2.0
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.plasmoid 2.0
Item {
id: widget
Plasmoid.icon: 'starred-symbolic'
Plasmoid.fullRepresentation: PlasmaComponents3.Label {
text: plasmoid.icon
// OR
// text: widget.Plasmoid.icon
}
}
Plasmoid properties
Property | Type | Notes |
---|---|---|
Plasmoid.activationTogglesExpanded | bool | Keyboard shortcut will toggle Plasmoid.expanded . Since KDE Frameworks 5.76, this is true by default. |
Plasmoid.apiVersion | int | Due not use. Always returns 0 . Source code. |
Plasmoid.associatedApplication | string | |
Plasmoid.associatedApplicationUrls | QList<QUrl> | |
Plasmoid.availableScreenRect | rect | |
Plasmoid.availableScreenRegion | QVariantList | |
Plasmoid.backgroundHints | Plasma::Types::BackgroundHints | Documentation. Turn off the desktop widget bg. |
Plasmoid.busy | bool | Draw the BusyIndicator overtop the widget. |
Plasmoid.compactRepresentation | Component | Documentation. The smaller "icon" view view of the widget shown in the panel. |
Plasmoid.compactRepresentationItem | Item | The instance of the compactRepresentation Component. May be null on load if not visible. |
Plasmoid.configuration | KDeclarative::ConfigPropertyMap | Documentation. Provides access to all user configurable values as sub-properties. |
Plasmoid.configurationRequired | bool | Wither to show a Configure button on top of the compact/full representation. It may look better to create your own button that calls plasmoid.action("configure").trigger() . |
Plasmoid.configurationRequiredReason | string | Not currently implemented to do anything. |
Plasmoid.constraintHints | Plasma::Types::ConstraintHints | |
Plasmoid.containmentDisplayHints | Plasma::Types::ContainmentDisplayHints | |
Plasmoid.contextualActions | QList<QObject*> | |
Plasmoid.currentActivity | string | |
Plasmoid.editMode | bool | Only available to Containments like the "panel" widget. Used to toggle the global widget editing mode. |
Plasmoid.effectiveBackgroundHints | Plasma::Types::BackgroundHints | Documentation. The actual background hints the applet has based on backgroundHints and userBackgroundHints . |
Plasmoid.expanded | bool | |
Plasmoid.formFactor | Plasma::Types::FormFactor | |
Plasmoid.fullRepresentation | Component | Documentation. The full "popup" view of the widget. |
Plasmoid.fullRepresentationItem | Item | The instance of the fullRepresentation Component. Since widget popup's a lazy loaded, it is null until the popup is opened. |
Plasmoid.globalShortcut | QKeySequence | |
Plasmoid.hideOnWindowDeactivate | bool | Set to false to "pin" the widget's full representation dialog open when out of focus. |
Plasmoid.icon | string | Example |
Plasmoid.id | uint | This is an integer representing the widget instance. See Plasmoid.metaData.pluginId for the widget namespace. |
Plasmoid.immutability | Plasma::Types::ImmutabilityType | Detect if Kiosk mode has locked the widgets, or the user Lock Widget mode from Plasma 5.18 and below. |
Plasmoid.immutable | bool | true if either UserImmutable or SystemImmutable . |
Plasmoid.loading | bool | Always false when widget is running. |
Plasmoid.location | Plasma::Types::Location | Location of widget on the screen. |
Plasmoid.metaData | KPluginMetaData | Reads metadata.json (or metadata.desktop ). See the AboutPlugin.qml source code for examples. |
Plasmoid.metaData.authors | QVariantList | |
Plasmoid.metaData.category | string | |
Plasmoid.metaData.copyrightText | string | |
Plasmoid.metaData.dependencies | QStringList | |
Plasmoid.metaData.description | string | |
Plasmoid.metaData.extraInformation | string | |
Plasmoid.metaData.fileName | string | |
Plasmoid.metaData.formFactors | QStringList | |
Plasmoid.metaData.iconName | string | |
Plasmoid.metaData.initialPreference | int | |
Plasmoid.metaData.isEnabledByDefault | bool | |
Plasmoid.metaData.isHidden | bool | |
Plasmoid.metaData.isValid | bool | |
Plasmoid.metaData.license | string | |
Plasmoid.metaData.licenseText | string | |
Plasmoid.metaData.metaDataFileName | string | |
Plasmoid.metaData.mimeTypes | QStringList | |
Plasmoid.metaData.name | string | The translated widget Name . Also see Plasmoid.title |
Plasmoid.metaData.otherContributors | QVariantList | |
Plasmoid.metaData.pluginId | string | Documentation. The widget namespace. Id in metadata.json , or X-KDE-PluginInfo-Name in metadata.desktop . |
Plasmoid.metaData.rawData | QJsonObject | |
Plasmoid.metaData.serviceTypes | QStringList | |
Plasmoid.metaData.translators | QVariantList | |
Plasmoid.metaData.version | string | Reads Version in metadata.json or X-KDE-PluginInfo-Version in metadata.desktop . |
Plasmoid.metaData.website | string | |
Plasmoid.nativeInterface | QObject | Documentation. Provides access to C++ properties by extending Plasma::Applet like the SystemTray. |
Plasmoid.pluginName | string | Documentation. The widget namespace. Alias of Plasmoid.metaData.pluginId |
Plasmoid.preferredRepresentation | Component | Force a representation and ignore Plasmoid.switchHeight . Example |
Plasmoid.rootItem | QObject | Reference the widget's root item. Cannot be used in the config dialog. |
Plasmoid.screen | int | |
Plasmoid.screenGeometry | rect | |
Plasmoid.self | AppletInterface | |
Plasmoid.status | Plasma::Types::ItemStatus | |
Plasmoid.switchHeight | int | The minimum height required to switch to fullRepresentation . |
Plasmoid.switchWidth | int | The minimum width required to switch to fullRepresentation . |
Plasmoid.title | string | The translated widget name. |
Plasmoid.toolTipItem | Item | |
Plasmoid.toolTipMainText | string | The mainText in the default tooltip layout. |
Plasmoid.toolTipSubText | string | The subText in the default tooltip layout. |
Plasmoid.toolTipTextFormat | int | The TextFormat of the subText. Defaults to PlainText . |
Plasmoid.userBackgroundHints | Plasma::Types::BackgroundHints | Documentation. The user specified background hint. |
Plasmoid.userConfiguring | bool |
Plasmoid.compactRepresentation
The compact representation uses DefaultCompactRepresentation.qml
by default. To summarize, it:
- Draws the
plasmoid.icon
using aKirigami.Icon
- Defines a
MouseArea
to toggle theexpanded
property which displays the full representation.
Plasmoid.fullRepresentation
If there's enough room (more than Plasmoid.switchHeight
) then the widget's full representation can be drawn directly in the panel or on the desktop. If you want to force this behaviour you can set Plasmoid.preferredRepresentation
.
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
If there isn't enough room, then the widget will display Plasmoid.compactRepresentation
instead, and the full representation will be visible when plasmoid.expanded
is true
.
In a plasma widget, the full representation will be shown in a
PlasmaCore.Dialog
which you cannot access directly. You can manipulate the dialog with:
- Set
Layout.preferredWidth
andLayout.preferredHeight
in your full representationItem
to change to dialog size. - Set
Plasmoid.hideOnWindowDeactivate
to prevent the dialog from closing. You can use this to have a configurable "pin" like the digital clock widget does.
The dialog's source code can be found in CompactApplet.qml
to see the exact behavior.
import QtQuick 2.0
import QtQuick.Layouts 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.plasmoid 2.0
Item {
// Always display the compact view.
// Never show the full popup view even if there is space for it.
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
Plasmoid.fullRepresentation: Item {
Layout.minimumWidth: label.implicitWidth
Layout.minimumHeight: label.implicitHeight
Layout.preferredWidth: 640 * PlasmaCore.Units.devicePixelRatio
Layout.preferredHeight: 480 * PlasmaCore.Units.devicePixelRatio
PlasmaComponents.Label {
id: label
anchors.fill: parent
text: "Hello World!"
horizontalAlignment: Text.AlignHCenter
}
}
}
Plasmoid.icon
As mentioned in the setup widget metadata.json
section, by default the plasmoid icon is populated with the Icon
value in metadata.json
.
To set a dynamic or user configurable icon, you will need to assign an icon name to Plasmoid.icon
.
You can search for icon names in the /usr/share/icon
folder. You can also look for an icon name by right clicking your app launcher widget then editing the icon in its settings. It uses a searchable interface and lists them by category. Plasma's SDK also has the Cuttlefish app (screenshot) which you can install with sudo apt install plasma-sdk
.
Also checkout the configurable panel icon example
import QtQuick 2.0
import org.kde.plasma.plasmoid 2.0
Item {
id: widget
property bool hasUnread: true
Plasmoid.icon: hasUnread ? "mail-unread" : "mail-message"
Timer {
interval: 1000
repeat: true
running: true
onTriggered: widget.hasUnread = !widget.hasUnread
}
}
Plasmoid.configuration
This property provides access to the values user configurable values. You can easily access config values with plasmoid.configuration.varName
. By default it populates with the keys and values in config/main.xml
. You can easily write to plasmoid.configuration.varName = "value"
to change the value for the user.
Read more about configuration and the config dialog in it's section of the tutorial.
The user's configuration is serialized to ~/.config/plasma-org.kde.plasma.desktop-appletsrc
when the plasmashell
process terminates and is only loaded at startup.
Since: KDE Frameworks 5.78, you can reference the default value of plasmoid.configuration.varName
with plasmoid.configuration.varNameDefault
.
Since: KDE Frameworks 5.89, the
KDeclarative::ConfigPropertyMap
datatype was deprecated and will eventually change to KConfig's
KConfigPropertyMap
.
import QtQuick 2.0
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.plasmoid 2.0
RowLayout {
id: widget
PlasmaComponents.Label {
text: i18np("%1 Click", "%1 Clicks", plasmoid.configuration.numClicked)
}
PlasmaComponents3.Button {
icon.name: "value-increase-symbolic"
text: i18n("Add")
onClicked: plasmoid.configuration.numClicked += 1
}
}
Plasmoid.backgroundHints
PlasmaCore.Types.DefaultBackground
(default) is equal toStandardBackground
.PlasmaCore.Types.StandardBackground
The standard background from the theme is drawn.PlasmaCore.Types.TranslucentBackground
An alternate version of the background is drawn, usually more translucent.PlasmaCore.Types.ShadowBackground
The applet won't have a svg background but a drop shadow of its content done via a shader. The text color will also invert.PlasmaCore.Types.NoBackground
This property is used to hide a desktop widget background. An example would be the Analog Clock widget.PlasmaCore.Types.ConfigurableBackground
Allows the user to toggle betweenStandardBackground
andShadowBackground
. Note that this is a bit flag to be used with another enum value.
To use ConfigurableBackground
, combine the flag with another value with the bitwise OR operator |
.
PlasmaCore.Types.NoBackground | PlasmaCore.Types.ConfigurableBackground
Note: For ShadowBackground
, make sure you use PlasmaCore.ColorScope.colorGroup
in your IconItem
to have the symbolic icons follow the text color.
PlasmaCore.IconItem {
colorGroup: PlasmaCore.ColorScope.colorGroup
}
import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0
Item {
id: widget
Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground
}
import QtQuick 2.0
import QtQuick.Layouts 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents3
import org.kde.plasma.plasmoid 2.0
Item {
id: widget
Plasmoid.icon: 'starred-symbolic'
Plasmoid.backgroundHints: PlasmaCore.Types.StandardBackground | PlasmaCore.Types.ConfigurableBackground
// Plasmoid.backgroundHints: PlasmaCore.Types.ShadowBackground | PlasmaCore.Types.ConfigurableBackground
// Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground | PlasmaCore.Types.ConfigurableBackground
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
Plasmoid.fullRepresentation: RowLayout {
PlasmaCore.IconItem {
source: plasmoid.icon
colorGroup: PlasmaCore.ColorScope.colorGroup
Layout.fillHeight: true
Layout.preferredWidth: height
}
PlasmaComponents3.Label {
text: "Text"
font.pointSize: 30
}
}
}
metadata.json
The common metadata.json
properties are covered in the setup widget section.
metadata.desktop
is the older format while metadata.json
is the newer replacement format. The .desktop
file is simpler to script using kreadconfig5
which is the reason why this tutorial prefers it in certain places like translations.
You can read the generated
C++ API Documentation for metadata.json
for the json schema. The full list of properties for the older metadata.desktop
properties for widgets is defined in the Plasma/Applet
service type.
Name, Description
Name[fr]
. The translated Name
is used in the "Add Widgets" list. The Description
(previously known as Comment
in the metadata.desktop
) is only used for the default tooltip subtext when the widget is added to a panel.{
"KPlugin": {
"Description": "Month display with your appointments and events",
"Description[fr]": "Vue mensuelle avec vos rendez-vous et évènements",
"Name": "Calendar",
"Name[fr]": "Calendrier"
}
}
[Desktop Entry]
Name=Calendar
Name[fr]=Calendrier
Comment=Month display with your appointments and events
Comment[fr]=Vue mensuelle avec vos rendez-vous et évènements
Icon
Icon
is the icon name associated with the widget. You can search for icon names in the /usr/share/icon
folder. You can also look for an icon name by right clicking your app launcher widget then editing the icon in its settings. It uses a searchable interface and lists them by category. Plasma's SDK also has the Cuttlefish app which you can install with sudo apt install plasma-sdk
.{
"KPlugin": {
"Icon": "office-calendar",
}
}
[Desktop Entry]
Icon=office-calendar
Id
The Id
(or X-KDE-PluginInfo-Name
in metadata.desktop
) needs to be a unique name, since it's used for the folder name it's installed into. You could use com.github.zren.helloworld
if you're on github, or use org.kde.plasma.helloworld
if you are planning on contributing the widget to KDE. You should consider this the widget's namespace.
To view the currently installed namespaces use:
❯ kpackagetool5 --type Plasma/Applet --list
Listing service types: Plasma/Applet in ~/.local/share/plasma/plasmoids/
com.github.zren.helloworld
❯ kpackagetool5 --type Plasma/Applet --list --global
Listing service types: Plasma/Applet in /usr/share/plasma/plasmoids/
org.kde.desktopcontainment
org.kde.kdeconnect
org.kde.kscreen
org.kde.milou
org.kde.panel
org.kde.plasma.activitybar
org.kde.plasma.activitypager
org.kde.plasma.addons.katesessions
...
~/.local/share/plasma/plasmoids/com.github.zren.helloworld/
/usr/share/plasma/plasmoids/com.github.zren.helloworld/
{
"KPlugin": {
"Id": "com.github.zren.helloworld",
}
}
[Desktop Entry]
X-KDE-PluginInfo-Name=com.github.zren.helloworld
Category
The Category
(or X-KDE-PluginInfo-Category
in metadata.desktop
) is used to filter widgets in the widget list.
{
"KPlugin": {
"Category": "Date and Time",
}
}
[Desktop Entry]
X-KDE-PluginInfo-Category=Date and Time
Accessibility
: tools that help those with special needs or disabilities use their computerApplication Launchers
: application starters and file openers.Astronomy
: anything to do with the night sky or other celestial bodies.Date and Time
: clocks, calendars, scheduling, etcDevelopment Tools
: tools and utilities to aid software developersEducation
: teaching and educational aidesEnvironment and Weather
: add-ons that display information regarding the weather or other environmentally related dataExamples
: samples that are not meant for production systemsFile System
: anything that operates on files or the file system as its primary purpose, such as file watchers or directory listings. Simply using a file as storage does not qualify the add-on for this category.Fun and Games
: for games and amusementsGraphics
: for add-ons where displaying images, photos or graphical eye candy is the primary purposeLanguage
: add-ons whose primary purpose is language related, such as dictionaries and translators.Mapping
: geography and geographic data add-onsMultimedia
: music and video.Online Services
: add-ons that provide an interface to online services such as social networking or blogging sites. If there is another more appropriate category for the add-on given the topic (e.g. mapping if the applet's purpose is to show maps), even if the data is retrieved from the Internet prefer that other category over this one.System Information
: display and interaction with information about the computer such as network activity, hardware health, memory usage, etcUtilities
: Useful tools like calculatorsWindows and Tasks
: managers for application windows and/or tasks, such as taskbars
This list was taken from: https://techbase.kde.org/Projects/Plasma/PIG
KPackageStructure
KPackageStructure
is a string to identify the associated
KPackage::PackageStructure
. For a plasma widget, it should be Plasma/Applet
.
Note
In desktop files, theServiceTypes
key was defined instead.
This key is however deprecated and desktop files will no longer be supported in KF6.
To convert a desktop file to json, you can run the desktoptojson -i metadata.json
command.
The ServiceTypes
-> KPackageStructure
change must be done manually{
"KPackageStructure": "Plasma/Applet"
}
[Desktop Entry]
X-KDE-ServiceTypes=Plasma/Applet
X-Plasma-API, X-Plasma-MainScript
X-Plasma-API
tells plasma what script engine to use. declarativeappletscript
is the standard QML
loader.
X-Plasma-MainScript
is the entry point of your qml code. The default value is ui/main.qml
.
Note
In Plasma 6, it is no longer possible to specify a custom mainscript. Instead,ui/main.qml
is used as the entry point.
The X-Plasma-MainScript
entry may be omitted from the metadata in both Plasma 5 and 6.
X-Plasma-API
may also be removed in KF6, but is needed in KF5.{
"X-Plasma-API": "declarativeappletscript",
"X-Plasma-MainScript": "ui/main.qml"
}
[Desktop Entry]
X-Plasma-API=declarativeappletscript
X-Plasma-MainScript=ui/main.qml
X-Plasma-Provides (Alternatives)
A Plasmoid can specify the type of functionality it offers, for example whether it's a clock, an application launcher, etc. This mechanism is used to list alternative plasmoids for a certain function. When you open the context menu of the Application Launcher (aka kickoff) in the Plasma desktop panel, you'll see that a number of different Plasmoids are offered here as alternatives, like the Application Menu (aka kicker) and Application Dashboard (aka kickerdash). All three of these widgets define:
{
"X-Plasma-Provides": [
"org.kde.plasma.launchermenu"
]
}
[Desktop Entry]
X-Plasma-Provides=org.kde.plasma.launchermenu
These "Provides" are in fact arbitrary, so you can choose your own here. The field accepts multiple values separated by a comma. Here are some possible values that are used throughout Plasma:
org.kde.plasma.launchermenu
: App Launcher Menusorg.kde.plasma.multimediacontrols
: Multimedia controlsorg.kde.plasma.time
: Clocksorg.kde.plasma.date
: Calendarsorg.kde.plasma.time,org.kde.plasma.date
: Clocks with calendars (Eg: Digital Clock)org.kde.plasma.powermanagement
: Power management (Eg: Battery and Brightness)org.kde.plasma.notifications
: Notificationsorg.kde.plasma.removabledevices
: Removable devices, auto mounter, etc.org.kde.plasma.multitasking
: Task switchersorg.kde.plasma.virtualdesktops
: Virtual desktop switcherorg.kde.plasma.activities
: Switchers for Plasma activitiesorg.kde.plasma.trash
: Trash / file deletion
You can search plasma's code for more examples:
- Search
plasma-workspace
forX-Plasma-Provides
- Search
plasma-desktop
forX-Plasma-Provides
- Search
kdeplasma-addons
forX-Plasma-Provides
X-Plasma-NotificationArea (System Tray)
The Media Controller widget serves as a good example since it uses most of the systemtray metadata features. Its metadata contains the following:
{
"KPlugin": {
"EnabledByDefault": true
},
"X-Plasma-DBusActivationService": "org.mpris.MediaPlayer2.*",
"X-Plasma-NotificationArea": "true",
"X-Plasma-NotificationAreaCategory": "ApplicationStatus"
}
[Desktop Entry]
X-KDE-PluginInfo-EnabledByDefault=true
X-Plasma-NotificationArea=true
X-Plasma-NotificationAreaCategory=ApplicationStatus
X-Plasma-DBusActivationService=org.mpris.MediaPlayer2.*
By specifying X-Plasma-NotificationArea
, this widget will be found by the systemtray widget.
EnabledByDefault
will make sure it's enabled in the systemtray by default.
It's prudent for the widget to also set the X-Plasma-NotificationAreaCategory
so that the icons are grouped together. Its allowed values are:
ApplicationStatus
: indicates that this item represents an active applicationHardware
: indicates that this item allows managing hardware (could be a battery monitor or the wifi applet)SystemServices
: indicates that this item shows information about system services, for example the status of file indexing, software updates, etc.
You can search plasma's code for more examples:
- Search
plasma-workspace
forX-Plasma-NotificationArea
- Search
plasma-desktop
forX-Plasma-NotificationArea
- Search
kdeplasma-addons
forX-Plasma-NotificationArea
X-Plasma-DBusActivationService
X-Plasma-DBusActivationService
will load and unload widgets in the systemtray automatically when a DBus service becomes available or is stopped. This is very convenient to load widgets automatically, so the user doesn't have to explicitly go to the notification area settings and enable or remove a widget.
An example of this is the Media Controller widget, which is auto-loaded as soon as an application starts offering the org.mpris.MediaPlayer2
DBus service in the session. As you can see in its metadata.json
file, X-Plasma-DBusActivationService
accepts wildcards which makes it a bit easier to match DBus names. This key can also be very useful to avoid having a widget loaded when it's unnecessary, so it can help to avoid visual clutter and wasted memory.
{
"X-Plasma-DBusActivationService": "org.mpris.MediaPlayer2.*"
}
[Desktop Entry]
X-Plasma-DBusActivationService=org.mpris.MediaPlayer2.*
Search plasma-workspace
for X-Plasma-DBusActivationService
for more examples.