Skip to content

Instantly share code, notes, and snippets.

@cestrand
Created August 15, 2015 23:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cestrand/5d1c4ee6486e176bed5d to your computer and use it in GitHub Desktop.
Save cestrand/5d1c4ee6486e176bed5d to your computer and use it in GitHub Desktop.
KDE Plasma 4 applet template for Qt Creator
#include "main.h"
#include <QPainter>
#include <plasma/theme.h>
MyPlasmaApplet::MyPlasmaApplet(QObject *parent, const QVariantList &args) : Plasma::Applet(parent, args)
{ // rather don't add other stuff here. Use init() instead
setBackgroundHints(DefaultBackground);
resize(200, 200);
}
MyPlasmaApplet::~MyPlasmaApplet()
{
}
void MyPlasmaApplet::init()
{
}
void MyPlasmaApplet::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
p->drawText(contentsRect, Qt::AlignTop|Qt::AlignHCenter, "Hello World!");
}
K_EXPORT_PLASMA_APPLET(myplasmaapplet, MyPlasmaApplet)
#ifndef MYPLASMAAPPLET_HEADER
#define MYPLASMAAPPLET_HEADER
#include <Plasma/Applet>
class MyPlasmaApplet : public Plasma::Applet {
Q_OBJECT
public:
MyPlasmaApplet(QObject* parent, const QVariantList &args);
~MyPlasmaApplet();
void init();
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect);
};
#endif // MYPLASMAAPPLET_HEADER
QT += core gui
CONFIG += plugin no_plugin_name_prefix release
TARGET = plasma_applet_myplasmaapplet
TEMPLATE = lib
HEADERS += main.h
SOURCES += main.cpp
INCLUDEPATH +="/usr/include/KDE/"
LIBS +=-lkdecore -lkdeui -lkutils -lkio
unix {
INSTALLS += target \
desktop
desktop.path = /usr/share/kde4/services/
desktop.files += plasma-applet-myplasmaapplet.desktop
target.path = /usr/lib/kde4/
target.files += plasma_applet_myplasmaapplet.so
}
DISTFILES += plasma-applet-myplasmaapplet.desktop
QMAKE_DISTCLEAN += *.so*
[Desktop Entry]
Name=My plasma applet
Comment=
Type=Service
ServiceTypes=Plasma/Applet
X-KDE-Library=plasma_applet_myplasmaapplet
X-KDE-PluginInfo-Name=myplasmaapplet
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Author=
X-KDE-PluginInfo-Email=
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment