[PyKDE] QSyntaxHighlighter issues
Phil Thompson
phil at riverbankcomputing.co.uk
Sat Sep 25 14:50:13 BST 2004
On Saturday 25 September 2004 12:00 pm, Eli Yukelzon wrote:
> Hi there.
> I'm trying to implement a HTML tag highlighting in QTextEdit
> I've subclassed the QSyntaxHighlighter and QTextEdit like this:
>
> class qh(QSyntaxHighlighter):
> def __init__(self, edit):
> QSyntaxHighlighter(edit)
>
> def highlightParagraph( text, lastPara ):
> regexp = re.compile( r'^([\\w-]+:\\s)')
> if( regexp.search( text ) != -1 ):
> font = textEdit().currentFont()
> font.setBold( True )
> self.setFormat( 0, regexp.matchedLength(), font )
>
> return 0
>
> class te(QTextEdit):
> def __init__ (self,parent = 0, name = ""):
> QTextEdit(parent,name)
> #self.setTextFormat( Qt.PlainText )
> self.sh = qh(self)
>
> but on startup i get this exception:
> attributeError, sipThis
> in QSyntaxHighlighter constructor.
>
> What am i doing wrong? Maybe someone already implemented this, and I'm
> just reinventing the wheel?
You aren't passing self to the superclass __init__() methods.
Phil
More information about the PyQt
mailing list