We will write a "hello world"-KPart here. And we will write a MainWindow to hold this KPart. A KPart also gives you the flexibility to be integrated into kontact or konqueror, but we will do this later. So, the "hello world"-KPart only consists of a pushbutton labeled "hello world". We chose a pushbutton because it is the easiest viewable thing to create. It does not trigger an action on your click. The following is what you do

* write a subclass mypart of KParts::Part

* write a subclass mypart of KParts::Part

** because [http://api.kde.org/4.x-api/kdelibs-apidocs/kparts/html/classKParts_1_1Part.html#399fea8c8f8d4ee321118d1ec85775db setWidget] is protected

** because [http://api.kde.org/4.x-api/kdelibs-apidocs/kparts/html/classKParts_1_1Part.html#399fea8c8f8d4ee321118d1ec85775db setWidget] is protected

Line 13:

Line 13:

* write main.cpp

* write main.cpp

** use new mypart(mw) to get your part into your main window

** use new mypart(mw) to get your part into your main window

+

+

We will use 4 files to do this:

+

* CMakeLists.txt to ease building work

+

* main.cpp to show our MainWindow

+

* mypart.h to declare our classes

+

* mypart.cpp to implement our classes

== CMakeLists.txt ==

== CMakeLists.txt ==

Revision as of 12:27, 10 February 2008

Contents

Introduction

Kontact is a KDE PIM (personal information management) framework that allows embedding several pim applications like kmail and korganizer as plugins into one window. Kontact plugins are KParts that get loaded at runtime. So, this is a good time to learn how to write a kPart... Read on.

Writing a KPart

We will write a "hello world"-KPart here. And we will write a MainWindow to hold this KPart. A KPart also gives you the flexibility to be integrated into kontact or konqueror, but we will do this later. So, the "hello world"-KPart only consists of a pushbutton labeled "hello world". We chose a pushbutton because it is the easiest viewable thing to create. It does not trigger an action on your click. The following is what you do