[PyQt] Is it possible to override/extend QTextCursor?
Phil Thompson
phil at riverbankcomputing.co.uk
Sun Jan 6 18:54:23 GMT 2008
On Sunday 06 January 2008, Aaron Digulla wrote:
> Hello,
>
> 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())
> edit.setTextCursor(cursor)
>
> edit.append('x')
>
> 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?
You can't overload non-virtual functions.
Phil
More information about the PyQt
mailing list