Desktop widget tutorial
Default widgets
Learn by example
You can learn by example by reading SonicDE's default widgets. Most of them are compiled into plugins, in plasma/applets/ in the Qt plugin directory, so read their source code: sonic-desktop-interface and sonic-workspace-addons have most of them.
A few widgets are plain packages in /usr/share/plasma/plasmoids/, such as org.kde.plasma.systemmonitor. Widgets you download are installed the same way, in ~/.local/share/plasma/plasmoids/.
To fork a widget that is a plain package, copy its folder to ~/.local/share/plasma/plasmoids/ and rename it. Then change the Id in its metadata.json file to match the new folder name, change the Name so you can tell it apart from the widget you forked, and delete the translated lines such as Name[fr].
Finally, run plasmawindowed with the new Id to quickly test the fork.
mkdir -p ~/.local/share/plasma/plasmoids
cp -r /usr/share/plasma/plasmoids/org.kde.plasma.systemmonitor/ ~/.local/share/plasma/plasmoids/com.example.mymonitor
cd ~/.local/share/plasma/plasmoids/com.example.mymonitor
sed -i 's/org.kde.plasma.systemmonitor/com.example.mymonitor/' ./metadata.json
sed -i '/^\s*"Name\[/ d' ./metadata.json
sed -i '/^\s*"Description\[/ d' ./metadata.json
plasmawindowed com.example.mymonitor
Fix any trailing comma errors these commands leave in metadata.json: there must be no trailing comma after the last entry of an object.