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

David Boddie david at boddie.org.uk
Sun Feb 8 20:56:41 GMT 2009


On Sun Feb 8 17:31:08 GMT 2009, r wrote:
> On Sun, Jan 6, 2008 at 7:49 PM, David Boddie <david at boddie.org.uk> wrote:

[Reimplementing QTextCursor.insertText() methods]

> > Neither of those functions are virtual in Qt. This means that Qt will
> > always call the original QTextCursor::insertText() versions in preference
> > to your version, though you should be able to call your implementation
> > from Python.
>
> Is it a limitation of PyQt bindings or Qt itself? Is there any
> workaround available (at PyQt level or above)?

It might be possible to do something deeper in the text handling classes,
though nothing obvious springs to mind right now.

> I can't believe this to be a dead end situation - what's the point of
> having a mechanism for switching the cursor if there is no way to
> modify it? This seems to be a pretty general issue, potentially
> affecting many other Qt classes as well.

I seem to remember that the cursor is intended to be merely an interface
for accessing documents.

> As Aaron has pointed out, an alternative would be to rewrite the whole
> event handling procedure, which is hardly a solution.

I suspect that you would be better off trying to respond to changes in the
document instead, probably by handling the signals emitted by each
QTextDocument instance. I don't think that the rich text classes were
designed to be extended in this way - most of the flexibility is built
into the text layout engine, but this isn't exactly easy to extend for
most people.

What are you using QTextCursor for, and in what way do you need to extend it?

David


More information about the PyQt mailing list