Development/Tutorials/Writing kontact plugins

< Development‎ | Tutorials
Revision as of 10:27, 10 February 2008 by Tstaerk (Talk | contribs) (Writing a KPart)

Jump to: navigation, search

Kontact plugins are KParts that get loaded at runtime. To integrate your KPart into kontact, you will need to have a .desktop file like this:

ls /home/kde-devel/kde/share/kde4/services/kontact/
akregatorplugin.desktop     knotesplugin.desktop
akregatorplugin3.2.desktop  korganizerplugin.desktop
journalplugin.desktop       newstickerplugin.desktop
kaddressbookplugin.desktop  plannerplugin.desktop
karmplugin.desktop          specialdatesplugin.desktop
kmailplugin.desktop         summaryplugin.desktop
kmobiletools.desktop        todoplugin.desktop
knodeplugin.desktop         weatherplugin.desktop

Writing a KPart

The following is what you do

  • write a subclass mypart of KParts::Part
    • because setWidget is protected
    • use a Widget in it and use setWidget to get your widget into the KPart
  • write a subclass mypartmainwindow of KParts::MainWindow
  • write main.cpp
    • use new mypart(mw) to get your part into your main window


PROJECT( kdepart )

SET(kdepartSources main.cpp mypart.cpp)

KDE4_ADD_EXECUTABLE(kdepart ${kdepartSources})



  1. include <kdebug.h>
  2. include <KPushButton>
  3. include "mypart.h"
  4. include <QWidget>

mypart::mypart(QObject* parent) {

 kDebug() << "Entering mypart";
 QWidget* mywidget=new QWidget();
 KPushButton* button=new KPushButton("ho",mywidget);


mypartmainwindow::mypartmainwindow(QWidget* parent, Qt::WindowFlags f) {

 kDebug() << "Entering mypartmainwindow";
 mypart* mypart1=new mypart(this);


Using your kPart

You can use konqueror to display your kpart: konqueror -> Settings -> Configure Konqueror -> Web browsing -> Plugins

See also

Content is available under Creative Commons License SA 4.0 unless otherwise noted.