[PyQt] Pimping QTextEdit

Tero Niemi talamus at gmail.com
Sun Nov 16 02:27:07 GMT 2008


Hello,

I found your old post:

    http://www.riverbankcomputing.com/pipermail/pyqt/2008-January/018310.html

and I am currently playing with the exactly same idea -- to pimp up
QTextEditor class into non-WYSIWYG editor with a style support, and
the reason is: to write a Writer's Text Editor.

For a long time I have been searching for an open source replacement
for Microsoft Word. Something simple yet poweful. I have tried, so
far:

 * Open Office -- Unusable for professional writing because lack of
the "Normal" mode (draft mode)
 * Liquid Story Binder XE -- Great tool, but unicode support sucks.
Non ISO 8859-1 characters render funnily.
 * DarkRoom -- Unicode support sucks. Non-ISO 8859-1 characters render funnily.
 * JDarkRoom -- Has a java 1.6.0-related scroll-screen-mess-problem.
With 1.5.0 works, but anti-aliasing sucks and some fonts do not work
at all.
 * Q10 -- Unicode support sucks. Non ISO-8859-1 characters render funnily.
 * OpenQ10 -- Not finished. Unicode support sucks.
 * TextRoom -- Unicode seems to work, but not finished. Buggy here and there.

In this point I started wondering how difficult could it be to write
your own simple editor. As an old C++ coder I downloaded the QT kit
and made some preliminary tests. My notes so far:

 * The HTML route is a wrong way to go. Do not go there.
 * You need to be able to control two set of styles: paragraph
(QTextBlock) level and character (QTextFragment) level.
 * Make all edits via QTextCursor.
 * QTextEditor inserts new QTextFormats automagically into the
document. You cannot create a closed subset of QTextFormats and trust
that QTextEditor stays within that set.

So the question is, how the implement the styles and force QTextEditor
to use them? The correct place to store the style data *seems* to be:

    reading:  value = QTextFormat.property(QTextFormat::UserProperty +
myOwnStyleId)
    writing:  QTextFormat.setProperty(QTextFormat::UserProperty +
myOwnStyleId, value)

QTextEditor preserves intelligently this user defined metadata, like
it was a order to bold the text, or underline it. This means you have
to write your own applyStyle, mergeStyle and clearStyle -slots that
manage this metadata, grap the signals and process them manually.

This in theory.
Simple and clear, isn't it. :)

How I wish there would be an editor that:

* Had a working unicode support
* Rendered all characters beautifully
* Had a no nonesense fullscreen view
* Would keep the cursor in the middle of the screen while writing (à
la WriteRoom)
* Allowed simple paragraph style classes (quotes, lyrics, etc.) à la
Liquid Story Binder
* Allowed simple character style classes (emphasis, silently spoken, etc.)
* Had perl style regex support for find and replace.
* Would read and write ODF format files (modifying only the
content.xml would be enough!)
* Would not touch those areas of ODF file that it would not understand.
* Would have a plugin interface for more features, like dictionaries,
thesaurii, etc.

That program would be like the "Normal Mode" of the Open Office. Only better.

Well, living in a dream...

Cheers,
Tero Niemi
-- 
talamus_(at)_gmail_dot_com



More information about the PyQt mailing list