开发者

Changing the color of a QTextBlock that is within a QTextDocument

开发者 https://www.devze.com 2022-12-23 21:49 出处:网络
Is there any other way to change the QTextLayout of a QTextBlock that is within a QTextDocument without having to subclass QAbstractTextDocumentLayout and call its documentChanged?I know that on a cal

Is there any other way to change the QTextLayout of a QTextBlock that is within a QTextDocument without having to subclass QAbstractTextDocumentLayout and call its documentChanged?

I know that on a call to QTextBlock::layout() const ; "the returned QTextLayout object can only be modified from the documentChanged implementation of a QAbstractTextDocumentLayou开发者_开发知识库t subclass" but I was wodering if there was any other way before I implemented it.

UPDATE basically I just want paragraphs(QTextBlock) that are longer than X characters to be highlighted and the rest to be normal.


Look at QSyntaxHighlighter http://doc.qt.io/qt-4.8/qsyntaxhighlighter.html

This pretty much will let you do exactly what you're trying to do.


Problem with changing block's layout directly is that it will inadvertently affect the layout of the currently active document layout (instance of the internal QAbstractTextDocumentLayout implementation) - it computes positions of QTextDocument elements only inside the documentChanged() and uses them whenever it needs to repaint or hit-test - so these things might get broken.

Can you elaborate on what you're trying to achieve?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号