KNotifications
- Basic Notifications
- Inline Reply Notification
- Creating Notifications Dynamically
- Further References
Basic Notifications
Getting started with notifications in QML is quite similar to how this also works in C++:
- Create a
KNotificiation
instance. - Customize it to your needs via its properties (labels, icons, actions, priorities, etc).
- Connect to its signals to react to the user interacting with the notification, by triggering its inline actions or by closing it.
- Eventually call its
KNotification::sendEvent()
method to show or re-show the notification.
Inline Reply Notifications
Inline reply notifications are also available. There's a small difference to C++ in that the reply action doesn't need to be explicitly managed but is created on demand behind the scenes.
Creating Notifications Dynamically
You might have a use-case that requires an arbitrary amount of dynamically created notifications rather than a fixed set of reusable instances. In that case the approach shown above might be too restrictive.
To address this it is possible to configure the auto-delete behavior of KNotification
objects. When used from C++ it's on by default for compatibility (but can also be switched off), in QML it's off by default and can be switched on when needed as shown in the following example.
Further References
There's a more complete and actually runnable pure-QML example in examples/notificationtester.qml
provided as part of the KNotifications source code.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Nov 6 2024 12:09:16 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.