Full text editor component


KTextEditor provides a powerful text editor component that you can embed in your application, either as a KPart or using the KF5::TextEditor library (if you need more control).

The text editor component contains many useful features, from syntax highlighting and automatic indentation to advanced scripting support, making it suitable for everything from a simple embedded text-file editor to an advanced IDE.



As with other KParts, you should use KParts::MainWindow as your main window. You can directly request "katepart", as in

if (service) {
m_part = service->createInstance<KParts::ReadWritePart>();

See the KParts documentation for more information on using KParts.


If you are using CMake, you need to have


(or similar) in your CMakeLists.txt file, and you need to link to KF5::TextEditor.

After that, you can use KTextEditor::Editor to create an editor instance, and use that to manage KTextEditor::Document instances.

#include <KTextEditor/Document>
#include <KTextEditor/Editor>
#include <KTextEditor/View>
// create a new document
// create a widget to display the document
KTextEditor::View *view = doc->createView(containerWidget);

See the documentation for these classes for more information.


Contributions to KTextEditor shall be licensed under LGPLv2+.

All files shall contain a proper "SPDX-License-Identifier: LGPL-2.0-or-later" identifier inside a header like:

SPDX-FileCopyrightText: 2021 Christoph Cullmann <[email protected]>
SPDX-License-Identifier: LGPL-2.0-or-later

Further Documentation

virtual Document * createDocument(QObject *parent)=0
Create a new document object with parent.
virtual View * createView(QWidget *parent, KTextEditor::MainWindow *mainWindow=nullptr)=0
Create a new view attached to parent.
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:146
Accessor interface for the KTextEditor framework.
Definition: editor.h:90
static Editor * instance()
Accessor to get the Editor instance.
Definition: ktexteditor.cpp:83
static Ptr serviceByDesktopName(const QString &_name)
A KParts derived class representing a text document.
Definition: document.h:185
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Jul 1 2022 05:06:22 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.