Contents

Abstract

Using the paintInterface method to display applets is a powerful, and sometimes even necessary way of working. For example, when you want to display a SVG graphic. But it is not the only method available to create a Plasmoid, however. Plasma comes with a number of widgets "tailored" for use in Plasmoids. In this tutorial we will create a very simple "Hello, world!" Plasmoid using Plasma widgets.

Let's take a deeper look at it. As in the main tutorial, we create our class by deriving from the PlasmaScripting::Applet class. In initialize, we quickly initialize the class. We use the init method instead to do all the dirty work of creating the applet and adding the widget needed to display the text.

First of all we tell Plasma that this applet does not have a configuration dialog (has_configuration_interface=). We then set the aspect ratio mode to a square (Plasma::Square). This is taken into account when someone resizes the applet. Next the background_hints= method sets the Plasmoid's background to the default Plasma background (Plasma::Applet.DefaultBackground) saving us from having to manually draw the background ourselves.

The third and most important step deals with creating a layout. It is a bit different than the standard Qt::LinearLayout seen in Qt, because it is done inside a Qt::GraphicsView used by Plasma. We want a simple, linear layout, and so we use a Qt::GraphicsLinearLayout, setting it to be horizontal (Qt::Horizontal).

Next we create a Plasma::Label. This is a widget that is Plasma aware and therefore uses all of the goodies provided by Plasma. For example, automatically changing its text color if the Plasma theme changes. We then use the text= method (analogous to the normal Qt::Label.text= method) to set our label text ("Hello, world!") and then add the label to the layout. Also, we set the applet's layout to be the one we have just defined using self.layout=. Finally we resize the applet to 125 x 125 pixels.