From February 4th until February 9th I attended a Plasma Mobile sprint in Berlin, Germany. I met a lot of people that share the vision of an open, privacy-friendly mobile platform. However, we all agree that such a platform can only succeed if there are enough people sharing that vision creating suitable apps for it. There already is a nice amount of mobile-friendly Linux apps, many of them created by the KDE Community, but of course we need more 🙂
One app that is essential for my use case is an app that allows me to check departures and routes for public transport. Since I’m not aware of any existing one I decided to do my own and share my road here. The purpose of this is to be educating for both me and you and to inspire you to create your own mobile-friendly Linux apps.
Like the other KDE mobile apps I’m going to use QML/QtQuick and Kirigami. QML is the declarative UI language from the Qt project. Unlike the older QWidgets it is designed with (embedded) touch systems in mind and thus is ideal for mobile apps. Kirigami is a set of QtQuick components designed for creating convergent mobile/desktop apps.
Unlike other KDE projects I’m not going to use C++ for the business logic. Instead I’m going to use Python, which is now officially supported by Qt. Since my Python skills are fairly basic this will be a fun challenge for me. Therefore take everything I write with a grain of salt and feel free to point out anything that is wrong or can be improved.
This won’t be a 100% complete reference for developing for Plasma Mobile, but I’ll try to cover as many different aspects as fit into the concept of this app. I’ll also try to focus on one aspect/feature/goal per post. Also most of this will not be specific to Plasma Mobile but will work on any desktop or mobile Linux.
So lets get started 🙂
Part 0: Basic application
Before getting started we need to install a few things. First of all we need Python (obviously) and Qt for Python. Qt for Python was formerly known as PySide2. You can install it via ‘pip install pyside2’. Next there is Kirigami. On Ubuntu you can install it via ‘sudo apt install qml-module-org-kde-kirigami2’.
After that we can start coding. The following main.py file is creating an app and loading the UI from a .qml file. The exact details are not too important at this point.
#!/usr/bin/env python3
from PySide2.QtGui import QGuiApplication
from PySide2.QtQml import QQmlApplicationEngine
if __name__ == "__main__":
app = QGuiApplication()
engine = QQmlApplicationEngine()
context = engine.rootContext()
engine.load("qml/main.qml")
if len(engine.rootObjects()) == 0:
quit()
app.exec_()
Next we need to define our UI in a QML file. To keep things organized we are going to put our QML files in a qml/ subfolder. Our first main.qml is rather simple
import QtQuick 2.2
import QtQuick.Controls 2.4
import org.kde.kirigami 2.0 as Kirigami
Kirigami.ApplicationWindow
{
width: 480
height: 720
Label {
text: "Hello world!"
anchors.centerIn: parent
}
}
width and height are a bit arbitrary since the window will always be maximized on the phone, but this way we get a somewhat realistic window on the desktop. Executing the python file should result in something like this

In the next post we are going to fill this window with more life using QtQuick and Kirigami components. Stay tuned 🙂
The source code will be available at https://invent.kde.org/nicolasfella/kstraba
For me there is an error on qml file, it says that module “org.kde.kirigami” is not installed, but “qml-module-org-kde-kirigami2” installed
LikeLike
I can reproduce the problem with PySide installed via pip. Try running ‘QML2_IMPORT_PATH=/usr/lib/x86_64-linux-gnu/qt5/qml python main.py’
LikeLike
On my arch laptop the path is `QML2_IMPORT_PATH=/usr/lib/qt/qml`
LikeLiked by 1 person
True 🙂 I have no idea why it’s not working OOTB though. I’ve filed https://bugreports.qt.io/browse/PYSIDE-949
LikeLike
Did you use pip install –user or sudo -H pip install.
LikeLike
Yes, I installed with –user argument, I prefer these libs on my home. I think this is the problem.
LikeLike
Hi, when I use QML2_IMPORT_PATH=/usr/lib/x86_64-linux-gnu/qt5/qml python main.py execute one error:
Cannot mix incompatible Qt library (version 0x50c00) with this library (version 0x50c01)
btw: QMake version 3.1
Using Qt version 5.12.0 in /usr/lib/x86_64-linux-gnu
LikeLike
Did you install PySide via pip? I think it is built against Qt 5.12.1 but the Qt on your system is 5.12.0
LikeLike
Yes, I installed by pip.
It would then be advisable to uninstall and install it as follows?: sudo apt-get install python3-pyside
LikeLike
python3-pyside seems to be PySide 1, which is based on Qt 4. Pyside 2 is based on Qt 5 and what we want, but I didn’t find a package for it in Ubuntu
LikeLike
Which version you have?, since it works properly for you.
LikeLike
I’m using Qt 5.12.1
LikeLike
thank for this post i really like this post
LikeLike
I am getting an error cannot install type into protected module qtquick.controls version 2
I have installed pyside2 via pip in a virtual environment and using the qml2_import_path to run the program.
I am on arch running the latest plasma with kirigami installed
LikeLike