Need underline ONE word in QPlainTextEdit [SOLVED]

I need underline only one word in text. I know it's line number and position in line. I do not want use syntax highlighter for this simple task. Just tried this code (Editor class is subclass of QPlainTextEdit):

but the underline did not appear. Even if remove latest two lines and try type - characters appear without underline. What is wrong here? I read following in docs:

bq. void QPlainTextEdit::setCurrentCharFormat ( const QTextCharFormat & format )
Sets the char format that is be used when inserting new text to format by calling QTextCursor::setCharFormat() on the editor's cursor. If the editor has a selection then the char format is directly applied to the selection.

and expected that selected text will be underlined. May be I missed some setting anywhere, but which one exactly?

I noticed that there is no call of underline allowing method. Just included

@ newcharfmt.setFontUnderline( true );@

before line 14 in the code. But this did not help. Even no any other font setting works. Tried make selection italic or else. Nothing works here. What is wrong? May be it doesn't work because of syntax highlighter is attached to this text?

remember that you're working on a COPY of the text cursor. You have to set it back before the calls to setCurrentCharFormat, or the QPlainTextEdit will not have the cursor's selection and thus that call won't do what you want;

you could just use QTextCursor::setCharFormat directly instead. Again, if you move the cursor (line 19), you MUST set it back.

Damn... With this underlining I suddenly lost syntax highlighting. :-( After call of setCurrentCharFormat( newcharfmt ); at line 13 all text except current line is shown without syntax highlighting. What the?...

exactly that's all. It works fine until call of setCurrentCharFormat(). After this call QtGUI engine redraws only current line (current block) with syntax highlighting. Other lines it redraws without highlighting - just black on white text. Of course each next changed line appears with highlighting.

I don't know what to do with that. GUI engine calls highlightBlock() method, not me. I tried update() or repaint() text after setCurrentCharFormat() but without effect.

For me this looks more like a small bug. I could not imagine situation where syntax highlighting in other blocks except current should be lost after character format change. May be in some exotic case it should. But I'm pretty sure by default it must keep highlighting. Syntax highlighting exists mostly for programming languages. Each of them requires highlighting in entire source code. For exotic cases there could be special bool parameter in QSyntaxHighlighter settings. Something like setHLcurrentBlock( bool b = false )