Bug 523675 - All widgets in the panel have an index of -1 in Plasma scripting
Summary: All widgets in the panel have an index of -1 in Plasma scripting
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Scripting (other bugs)
Version First Reported In: 6.6.6
Platform: Ubuntu Linux
: NOR normal
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-07-30 22:13 UTC by Aaron Rainbolt
Modified: 2026-08-13 15:11 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 6.8.0
Sentry Crash Report:


Attachments
What my panel looked like before running the script (105.81 KB, image/png)
2026-07-31 15:21 UTC, Aaron Rainbolt
Details
What I thought the panel would look like after running the script (108.26 KB, image/png)
2026-07-31 15:21 UTC, Aaron Rainbolt
Details
What the panel actually looks like after running the script (111.16 KB, image/png)
2026-07-31 15:22 UTC, Aaron Rainbolt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron Rainbolt 2026-07-30 22:13:58 UTC
DESCRIPTION
I'm attempting to write a Plasma script that will add a clickable icon widget next to an existing widget already in my panel. (This could be done via edit mode, but I'm scripting it so I can automate it across multiple machines.) According to https://develop.kde.org/docs/plasma/scripting/api/#widgets, I read a widget's `index` property to determine where it is in the panel, and can write to that property to change where it is in the panel. This however does not work; all widgets have an index of -1 when reading them, and writing a new value to a widget's index appears to be a no-op.

STEPS TO REPRODUCE
1. Open plasma-interactiveconsole.
2. Paste the following code in and run it:

```
panelIds.forEach((panelId) => {
    let panel = panelById(panelId);
    if (!panel) {
        return;
    }
    panel.widgetIds.forEach((appletWidgetId) => {
        let appletWidget = panel.widgetById(appletWidgetId);
        if (appletWidget.type === "org.kde.plasma.kickoff") {
            const newWidget = panel.addWidget('org.kde.plasma.icon');
            newWidget.index = appletWidget.index;
            newWidget.writeConfig( 'localpath', '/usr/share/applications/org.kde.kate.desktop' );
            newWidget.currentConfigGroup = [ 'General' ];
            newWidget.writeConfig( 'url', 'file:///usr/share/applications/org.kde.kate.desktop' );
        }
    }); 
});
```

OBSERVED RESULT
A Kate launcher icon is added at the "end" of the panel (the far right edge if using a horizontal panel at the bottom of the screen), far away from the Application Launcher button. If you print `appletWidget.index`, you will see it has a value of -1. Setting `newWidget.index` to a hardcoded positive value has no effect on the behavior.

EXPECTED RESULT
A Kate launcher icon is added right next to the Application Launcher button.

SOFTWARE/OS VERSIONS
Operating System: Kubuntu 26.04 LTS
KDE Plasma Version: 6.6.6
KDE Frameworks Version: 6.24.0
Qt Version: 6.10.2

ADDITIONAL INFORMATION
n/a
Comment 1 Aaron Rainbolt 2026-07-31 15:21:33 UTC
Created attachment 194738 [details]
What my panel looked like before running the script
Comment 2 Aaron Rainbolt 2026-07-31 15:21:53 UTC
Created attachment 194739 [details]
What I thought the panel would look like after running the script
Comment 3 Aaron Rainbolt 2026-07-31 15:22:09 UTC
Created attachment 194740 [details]
What the panel actually looks like after running the script
Comment 4 Marco Martin 2026-08-04 14:22:21 UTC
Indeed, in plasma6 applet.index is not implemented. now, i'm not sure how to actually implement it as it seems to be a stub since plasma5 (the old actual implementation seems to be KDE4 based)

I'll give it a try to see if i can have an implementation that works on the current panel architecture

in the meantime, a workaround that is as small as possible (and reliable for now) is:
    panelIds.forEach((panelId) => {
        let panel = panelById(panelId);
        if (!panel) {
            return;
        }
        panel.widgetIds.forEach((appletWidgetId) => {
            let appletWidget = panel.widgetById(appletWidgetId);
            if (appletWidget.type === "org.kde.plasma.kickoff") {
                const x = appletWidget.geometry.x + appletWidget.geometry.width / 2
                const y = appletWidget.geometry.y + appletWidget.geometry.height / 2
                const newWidget = panel.addWidget('org.kde.plasma.icon', x + 1,y + 1);
                //newWidget.index = appletWidget.index;
                newWidget.writeConfig( 'localpath', '/usr/share/applications/org.kde.kate.desktop' );
                newWidget.currentConfigGroup = [ 'General' ];
                newWidget.writeConfig( 'url', 'file:///usr/share/applications/org.kde.kate.desktop' );
            }
        }); 
    });
Comment 5 Marco Martin 2026-08-06 13:17:44 UTC
Git commit 6f2cbab5ca795d8ac2a05a4f6b9e2904829d931c by Marco Martin.
Committed on 06/08/2026 at 13:17.
Pushed by mart into branch 'master'.

Scripting: restore Applet::index property

on panels use the config to the index order
and use the reorderApplets() function that the panel containment exposes to apply a different index
Depends from https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/3926

M  +37   -21   shell/scripting/widget.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/6f2cbab5ca795d8ac2a05a4f6b9e2904829d931c
Comment 6 Marco Martin 2026-08-06 13:41:12 UTC
Git commit 21cbb732ab85093b6c89340fe93396edae824a35 by Marco Martin.
Committed on 06/08/2026 at 13:41.
Pushed by mart into branch 'master'.

Panel: expose reorderApplets() function for scripting

Expose a reorderApplets function which takes a list of applet
ids and reorders the known applets consistent to such list.

Depends from https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/6895

M  +17   -0    containments/panel/LayoutManager.js
M  +8    -0    containments/panel/main.qml

https://invent.kde.org/plasma/plasma-desktop/-/commit/21cbb732ab85093b6c89340fe93396edae824a35
Comment 7 Marco Martin 2026-08-13 14:31:31 UTC
Git commit afdd265164ecbf75ff129d49f8c644d510ebfcd3 by Marco Martin.
Committed on 13/08/2026 at 14:30.
Pushed by mart into branch 'Plasma/6.7'.

Scripting: restore Applet::index property

on panels use the config to the index order
and use the reorderApplets() function that the panel containment exposes to apply a different index
Depends from https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/3926


(cherry picked from commit 6f2cbab5ca795d8ac2a05a4f6b9e2904829d931c)

97e8d546 Scripting: restore Applet::index property
723a0db1 make index and setindex work

Co-authored-by: Marco Martin <notmart@gmail.com>

M  +37   -21   shell/scripting/widget.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/afdd265164ecbf75ff129d49f8c644d510ebfcd3
Comment 8 Bug Janitor Service 2026-08-13 14:33:59 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/3946
Comment 9 Marco Martin 2026-08-13 14:34:10 UTC
Git commit 4218bb0612913466e90258babdc596f7851c5e70 by Marco Martin.
Committed on 13/08/2026 at 14:33.
Pushed by mart into branch 'Plasma/6.7'.

Panel: expose reorderApplets() function for scripting

Expose a reorderApplets function which takes a list of applet
ids and reorders the known applets consistent to such list.

Depends from https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/6895


(cherry picked from commit 21cbb732ab85093b6c89340fe93396edae824a35)

e115f36d Panel: expose reorderApplets() function for scripting

Co-authored-by: Marco Martin <notmart@gmail.com>

M  +17   -0    containments/panel/LayoutManager.js
M  +8    -0    containments/panel/main.qml

https://invent.kde.org/plasma/plasma-desktop/-/commit/4218bb0612913466e90258babdc596f7851c5e70
Comment 10 Bug Janitor Service 2026-08-13 14:35:33 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/3947
Comment 11 Marco Martin 2026-08-13 14:41:34 UTC
Git commit 8655994ff47a6ba740a29727a7cf597cc2fa06c8 by Marco Martin.
Committed on 13/08/2026 at 14:32.
Pushed by mart into branch 'Plasma/6.6'.

Scripting: restore Applet::index property

on panels use the config to the index order
and use the reorderApplets() function that the panel containment exposes to apply a different index
Depends from https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/3926


(cherry picked from commit 6f2cbab5ca795d8ac2a05a4f6b9e2904829d931c)

97e8d546 Scripting: restore Applet::index property
723a0db1 make index and setindex work

Co-authored-by: Marco Martin <notmart@gmail.com>

M  +37   -21   shell/scripting/widget.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/8655994ff47a6ba740a29727a7cf597cc2fa06c8
Comment 12 Marco Martin 2026-08-13 15:11:37 UTC
Git commit b9feaa22f4fff6b3ec9e965f9b4a656db2ba10ac by Marco Martin.
Committed on 13/08/2026 at 14:34.
Pushed by mart into branch 'Plasma/6.6'.

Panel: expose reorderApplets() function for scripting

Expose a reorderApplets function which takes a list of applet
ids and reorders the known applets consistent to such list.

Depends from https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/6895


(cherry picked from commit 21cbb732ab85093b6c89340fe93396edae824a35)

e115f36d Panel: expose reorderApplets() function for scripting

Co-authored-by: Marco Martin <notmart@gmail.com>

M  +17   -0    containments/panel/LayoutManager.js
M  +8    -0    containments/panel/main.qml

https://invent.kde.org/plasma/plasma-desktop/-/commit/b9feaa22f4fff6b3ec9e965f9b4a656db2ba10ac