[PyQt] Is it possible to override/extend QTextCursor?

Aaron Digulla digulla at hepe.com
Sun Jan 6 18:23:39 GMT 2008


I tried to overload insertText() of QTextCursor like this:

from PyQt4.QtGui import QTextEdit, QTextCursor, QApplication
import sys

class MyCursor(QTextCursor):
    def __init__(self, doc):
        super(MyCursor, self).__init__(doc)

    def beginEditBlock(self):
        print 'beginEditBlock'
        super(MyCursor, self).beginEditBlock()

    def insertHtml(self, text):
        print 'insertHtml',repr(text)
        super(MyCursor, self).insertHtml(text)

    def insertText(self, text, format=None):
        print 'insertText',repr(text)
        super(MyCursor, self).insertText(text, format)

app = QApplication(sys.argv)

edit = QTextEdit()
cursor = MyCursor(edit.document())


print edit.toPlainText()

but this test only outputs "x". I've checked the C++ source of Qt4 and
it should call at least the methods defined above.

I'm using openSUSE Linux and python-qt4 4.3-19. The methods are defined
in qtextcursor.sip, only insertText() is confusing:

    void insertText(const QString &text);
    void insertText(const QString &text, const QTextCharFormat &format);

Which one will Python overload?

Any ideas what could be wrong?

Thanks a lot,

Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."

More information about the PyQt mailing list