PyQt4 4.4.4 : a bug with highlightBlock ?

Snouffy alexis.flesch at free.fr
Wed Nov 18 05:47:02 EST 2009


Hello everybody,

I've been trying to do some syntax highlighting using PyQt4. I ported
the example given in the documentation of Qt4 to Python. It works fine
on my computer at work (which has PyQt4 version 4.3.3) but doesn't on
my home computer (which has version 4.4.4) : it gets stuck in an
infinite loop.
Here is the code :

class MyHighlighter(QtGui.QSyntaxHighlighter):
    def __init__(self, edit):
        QtGui.QSyntaxHighlighter.__init__(self,edit)

    def highlightBlock(self, text):
        myClassFormat = QtGui.QTextCharFormat()
        myClassFormat.setFontWeight(QtGui.QFont.Bold)
        myClassFormat.setForeground(QtCore.Qt.darkMagenta)
        pattern = "\\b[A-Z_]+\\b"

        expression = QtCore.QRegExp(pattern)
        index = text.indexOf(expression);
        while (index >= 0):
            length = expression.matchedLength()
            self.setFormat(index, length, myClassFormat)
            index = text.indexOf(expression, index + length)


What am I missing ? Is this a known bug of version 4.4.4 ?

Thank you,

Alexis.



More information about the Python-list mailing list