PDA

View Full Version : QPlainTextEdit highlight selected line



ArkKup
2nd November 2011, 10:45
Hi,

I'm trying to write simple debugger. I'd like to highlight current line when stepping over.
With help of code editor example I was able to do it like this:



void MainWindow::StepOver_cmd(void)
{

QTextCursor cursor = dissasembly_widget->textCursor();

cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor);
dissasembly_widget->setTextCursor(cursor);

QList<QTextEdit::ExtraSelection> extraSelections;
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(Qt::cyan).darker(200);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidt hSelection, true);
selection.cursor = cursor;

selection.cursor.clearSelection();
extraSelections.append(selection);
dissasembly_widget->setExtraSelections(extraSelections);

}


but the problem is when user changes cursor position it obviously starts to highlight code in different place.
The problem is with

dissasembly_widget->textCursor(); //dissasembly_widget is QPlainTextEdit

but I dont know how to do it otherwise since there is no setBlock function.
Thanks in advance!