is there a way to change the background color of a QTextBlock in a QTextDocument without using a subclass of QAbstractTextDocumentLayout. I have tried many ways and the effects are null. I am trying from the textCursor() method of a QPlainTextEditor and it seems practically everything is const.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You could try the merge methods:
QTextCursor cur = edit->textCursor();
QTextCharFormat fmt;
fmt.setBackground(QBrush(Qt::gray));
cur.mergeBlockCharFormat(fmt);
回答2:
Could this example help you ?
http://qt.nokia.com/doc/4.6/demos-textedit.html
You can find it also in QtDemos, on Demonstrations->Text Edit.
Hope it helps!