Pergunta

I'd like to force a redraw over a QPlainTextEdit widget, because my highlighting rules changed. However, all lines and blocks aren't redrawn, respecting the new rules.

This is true because if I modify a line, the correct highlighting is applied, and I am happy. But I cannot force-modify each block to see any change!

Is there a way to force a redraw? I tried update() and similars, but nothing seems to work.

Thanks!

Foi útil?

Solução 2

You have to call QSyntaxHighlighter::rehighlight() to apply the new highlighting rules to the whole document.

Outras dicas

QPlainTextEdit inherits QAbstractScrollArea, so its content is located in viewport widget. Try this:

text_edit->viewport()->update();

You can try:

text_edit->repaint();

In my case simply calling rehighlight don't update view. In my case i want update highlight when cursor moves so:

void MyHighlighter::onSelectionChanged(int start, int end)
{
    _visibleCursor.setPosition(end);
    document()->documentLayout()->updateBlock(_visibleCursor.block());
    rehighlightBlock(_visibleCursor.block());
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top