开发者

How to change the background of a text bloc in a text document in Qt

开发者 https://www.devze.com 2022-12-24 06:04 出处:网络
is there a way to change the background color of a QTextBlock in a QTextDocument without using a subclass o开发者_Go百科f QAbstractTextDocumentLayout. I have tried many ways and the effects are null.I

is there a way to change the background color of a QTextBlock in a QTextDocument without using a subclass o开发者_Go百科f 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.


You could try the merge methods:

QTextCursor cur = edit->textCursor();
QTextCharFormat fmt;
fmt.setBackground(QBrush(Qt::gray));
cur.mergeBlockCharFormat(fmt);


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!

0

精彩评论

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

关注公众号