//------------------------------------------------------------------------- void CodeEditor::highlightErrorLine(int line) { if ( line < 1 ) { setExtraSelections( QList<QTextEdit::ExtraSelection>() ); return; } QList<QTextEdit::ExtraSelection> extraSelections; QColor lineColor = QColor(Qt::red).lighter(160); QTextBlock textBlock = document()->findBlockByNumber( line-1 ); QTextCursor textCursor( textBlock ); for ( int i = 0 ; i < textBlock.lineCount() ; i++ ) { QTextEdit::ExtraSelection selection; selection.format.setBackground(lineColor); selection.format.setProperty(QTextFormat::FullWidthSelection, true); selection.cursor = textCursor; for ( int down = 0 ; down < i ; down++ ) selection.cursor.movePosition( QTextCursor::Down ); selection.cursor.select( QTextCursor::LineUnderCursor ); extraSelections.append(selection); } setExtraSelections(extraSelections); }