QPlainTextEdit: how create gaps and highlight text blocks?
-
wrote on 10 Feb 2018, 01:56 last edited by
I am planning create visual diff tool like WInMerge. Two panels, there editors from example "CodeEditor". It Is possible make line numbers with gaps because coder has full control on line numbers. But how highlight many blocks of text? How deny edit on "gaps"? (another question is syntax highlight but it can be later)
-
wrote on 10 Feb 2018, 02:45 last edited by
Highligting, QTextEdit:
int begin = editor->document()->findBlockByNumber(5).position(); int end = editor->document()->findBlockByNumber(10).position(); QTextBlockFormat fmt; fmt.setProperty(QTextFormat::FullWidthSelection, true); fmt.setBackground(Qt::yellow); QTextCursor cursor(editor->document()); cursor.setPosition(begin, QTextCursor::MoveAnchor); cursor.setPosition(end, QTextCursor::KeepAnchor); cursor.setBlockFormat(fmt);
-
wrote on 10 Feb 2018, 12:18 last edited by AndrzejB 2 Oct 2018, 16:52
One warning: this correct makes one highlighted block, but is bad if I want create many blocks. mergeBlockFormat not helps. Maybe can I use QSyntaxHighlighter for it?
Is unsolved: MoveAnchor/KeepAnchor not let me multiple blocks, worse - I can't restore default block type.
QTextCursor cursor(editor->document()); cursor.setPosition(begin, QTextCursor::MoveAnchor); cursor.setPosition(end, QTextCursor::KeepAnchor); cursor.setBlockFormat(fmt); QTextBlockFormat fmtNormal; cursor.setPosition(begin, QTextCursor::MoveAnchor); cursor.setPosition(end, QTextCursor::KeepAnchor); cursor.setBlockFormat(fmtNormal);
This cut me document
I need:QTextBlock block = editor->document()->findBlockByLineNumber(begin); block.setBlockFormat(fmtNormal); <---this not compiles
1/3