Settings module (KCM) development
This tutorial will help you create a Plasma configuration module.
Last updated
This tutorial will help you create a Plasma configuration module.
Last updated
Settings in Plasma are provided by KDE Configuration Modules (KCM). These can be loaded by multiple wrapper applications such as systemsettings
on the desktop, plasma-settings
on mobile or kcmshell6
for standalone config windows. The source code for the different modules is split across different locations, such as or .
You can query the available KCMs using kcmshell6 --list
. To load an individual module in a standalone window pass its name to the wrapper application, e.g. systemsettings kcm_accounts
, plasma-settings -m kcm_kaccounts
, or kcmshell6 kcm_kaccounts
.
KCMs consist of a KPackage holding the QML UI and a C++ library holding the logic. Some legacy KCMs are based on QtWidgets, however this is not recommended for new KCMs and it's not possible to load these in plasma-settings
. In Plasma, new KCMs should be built using QML and .
As an example, we are going to create a time settings module that allows us to configure the time in our system. The basic structure of this hypothetical time settings module is the following:
There are two CMake files here, one inside src
folder and one in the root folder.
The CMakeLists.txt
file in the root folder declares the project and prepares the KCM for building. This is only needed if you build the KCM alone, but usually KCM is included with the project it's for. Therefore it's not necessarily needed, but you need to make sure the project includes the libraries its KCM needs as well.
What's different here is that we are using C++ code as a plugin for our QML code. This is why we don't have a main.cpp
: we only need the class that will provide the backend functionality for our KCM. kcoreaddons_add_plugin
creates such a plugin and installs it to the right location.
Here is where we would put any backend code that changes things behind the scenes. We can expose functions in here to our QML so that elements of our UI can be used to trigger backend functionality. This C++ code is then installed in our system on compilation in a KCM plugin directory, where upon execution the KCM can access and use it.
In this C++ file we define the constructor for the class in the previous file. We include some basic metadata about this KCM and we provide the buttons that we will want included in our window.
This .json
file provides metadata about our KCM. These entries specify the following:
Name
defines the name of the KCM which is shown in the settings app.
Description
is a short, one sentence description of the module.
FormFactors
defines on which kinds of devices this KCM should be shown.
X-KDE-System-Settings-Parent-Category
defines the category systemsettings5 is showing the module in.
X-KDE-Keywords
defines Keywords used for searching modules.
More complex layouts will require using a different root component. Each has its own use:
All we need to do now is compile and run our KCM. In this case, we are installing our KCM to ~/kde/usr
, a non-standard location, so that we don't risk messing up anything on our local environment.
Now that our KCM is installed, we can run it (that is, so long as we have executed source prefix.sh
, which includes our non-standard ~/kde/usr/
location in our current environment).
These CMake files contain a few packages of note: provides various classes that allow us to work with , and Config
includes the classes. You are likely to have seen most of the other packages elsewhere in this documentation; if not, which goes through a similar CMakeLists file line by line.
Here we are defining the class we will be using for our KCM. serves as the base class for all QML-based KCMs. You can read the linked API documentation to get a full description, and the KConfigXT page goes into more detail about how KConfigXT works.
As you can see, this is a very basic KCM QML file. We have used a component as the root component, and we have just included a label inside here.
Use for content that is vertically scrollable, such as ListView.
Use for arranging selectable items in a grid.
Use otherwise.