[PyQt] Feature request: give QsyntaxHighlighter access to the global offset

Edward K. Ream edreamleo at gmail.com
Mon Feb 9 14:41:06 GMT 2009


For my app, there is a lamentable hole in the QSyntaxHighlighter interface.
My app has been able to work around this hole, but it would be *so* much
better if the hole could be plugged.

The problem is that QSyntaxHighlighter.highlightBlock is passed only the
string to be colored, *not* the offset of that string in the entire text.

True, in a purely state-driven approach, this offset is not needed, but
Leo's colorizer is based on the jEdit pattern matchers, and the offset is
absolutely crucial.  Details omitted :-)

Rather than adding an offset arg to highlightBlock, it might be more
convenient for you and your users to add a new getter, say,
offsetOfHighlightedBlock, that would, when called from highlightBlock give
the desired global offset.  Whatever is easiest for you will be fine with
me.

For example, I want to do the following in the overridden highlightBlock
method::

def highlightBlock (self,s):

    all_s = self.w.text() # self.w is a QTextEdit
    i = self.offsetOfHighlightedBlock()
    assert s == all_s[i:i+len(s)]
    ...

Thanks.

Edward
--------------------------------------------------------------------
Edward K. Ream email: edreamleo at gmail.com
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090209/9336641d/attachment.html


More information about the PyQt mailing list