// This is the command that links your applet to the .desktop file
K_EXPORT_PLASMA_APPLET(tutorial1, PlasmaTutorial1)

endif

QRectF boundingRect()

The boundingRect() function tells plasma the actual size of the plasmoid, this is important because we need to know how much space is taken on screen.

Tip

If you have issues with your plasmoid leaving pixels behind when dragging this is almost always a result of a incorrect boudingRect()

void paintInterface(...)

You could call this the main function, since this paints the plasmoid on screen, here you define how you want your plasmoid to look.

K_EXPORT_PLASMA_APPLET ( <name>, <class> )

This is a small but very important part, this links your classname to the applet name in the .desktop file, if your applet doesn't seem to be loaded than chances are there is a difference between this and your .desktop file

Tip

The K_EXPORT_PLASMA_APPLET adds "plasma_applet_", please pay attention to this when setting up your .desktop file to avoid a name difference

The actual work file

Here is the body of the function, again with a lot of comments in between.

// First we create the objects to hold the icon and background image
KIcon icon("document");
Plasma::Svg* background = new Plasma::Svg("widgets/background",this);
// Tell the Plasma/Svg object to use the whole image,
// instead of parts of it.
background->setContentType(Plasma::Svg::SingleImage);

// Now we draw the applet, starting with the background
background->resize(boundingRect().width(),boundingRect().height());
background->paint(p,boundingRect().left(),boundingRect().top());