Examples of KTextTemplate use


The Books application from Qt Demos is modified to export the available data to a rendered html file. The example shows a use of the extends tag to override some parts of a base template. The templates can be edited to change the exported content without any recompiling. The themer has broad control over how the data os rendered and can even alter the structure of the presented data.

A simple export of the data

A coloured export of the data showing the use of the "<tt>cycle</tt>" tag.

A restructured export of the data showing the use of the "<tt>ifchanged</tt>" tag.


The codegen example shows how to use KTextTemplate for code generation in multiple languages. The application can be used to generate classes in C++, python and ruby based on the content of the dialog. The user can define properties, which are generated appropriately to the language. For C++ it uses the Q_PROPERTY macro and creates an accessor a mutator and a notify signal. It can also be used to generate methods with arguments of any type in each language.

The property and method configuration UI

The output of the codegen tool

Related blog article

Using Grantlee for code generation


The contacts application demostrates the use of the internationalization and localization features in KTextTemplate. The user can select several contacts, whose details are formatted in templates for display in different themes. All strings in the templates are translatable, and the numbers, dates and currencies can be localized. The Contacts example can be used with the Qt or the KDE localization systems.

A theme showing selected contacts in localized tables

An alternative theme showing a single table with localized headers.

Related blog article

Localization: Tricky issue

Html application framework

The htmlapps example demonstrates how string templates can form part of a larger platform for html based applications. The application consists of a an extensible set of templates containing html applications, a KTextTemplate plugin to extract data from rss feeds, and various infrastructure to handle local and remote network requests and render the result in WebKit.

Several html applications are part of the example, such as capabilities for showing weather information, flickr feeds, identica microblogging etc.

A weather application written in HTML

A flickr application written in HTML

Related blog article

Templating HTML Applications with Grantlee

Textedit application example

The textedit application example is a modified version of the same example which is bundled with Qt. The example shows how a custom type can be used in a text document and processed with the KTextTemplate::Textdocument library. It further demostrates how to add theming to the output using the KTextTemplate::Templates library.

Related blog article



KDE PIM started using KTextTemplate in its 4.6.0 release. The applications KJots and KAddressBook already use KTextTemplate::Templates to render content for user consumption.

This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.