[Interest] Bypass QTextCursor::mergeBlockFormat() Undo Stack

Josh jnfo-d at grauman.com
Thu Mar 11 19:33:02 CET 2021


Hi all,

I have a QSyntaxHighlighter that applies not just coloring/formatting, but 
also left/top margin, and text indent to the text to display it. It works 
great. But the changes to the margin/indent are made via QTextCursor, and 
they go onto the Undo stack, so it breaks undo/redo for the QTextEdit.

Does anyone have any idea of how I can change the margin/indent of a 
QTextBlock without affecting the undo stack? I want the margins/indent to 
be displayed but not viewed as changes to the underlying QTextDocument. 
I'd rather not have to roll my own undo/redo...

//code in void QSyntaxHighlighter::highlightBlock(const QString &txt)
//determine level of text
if(level)
{
   setCurrentBlockState(level);
   blkfmt.setTopMargin(10);
   blkfmt.setLeftMargin(((level)*2)*chW);
   blkfmt.setTextIndent((-level-1)*chW);
   myCur.mergeBlockFormat(blkfmt);
}

TIA,

Josh


More information about the Interest mailing list