[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Is it possible to override/extend QTextCursor?
From:       Phil Thompson <phil () riverbankcomputing ! co ! uk>
Date:       2008-01-06 18:54:23
Message-ID: 200801061854.23662.phil () riverbankcomputing ! co ! uk
[Download RAW message or body]

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
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic