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.
+2
A:
Hey,
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!
Andy M
2010-03-25 05:58:19
Thanks, my bad I was only looking inside the examples and not the demos, I wonder why they are not examples.
yan bellavance
2010-03-25 16:55:04
I wonder though if I will be able to do this programatically since the textedit only seems to modify the layout of a user selection. I will see as I go through the code :D
yan bellavance
2010-03-25 17:00:40
+1
A:
You could try the merge methods:
QTextCursor cur = edit->textCursor();
QTextCharFormat fmt;
fmt.setBackground(QBrush(Qt::gray));
cur.mergeBlockCharFormat(fmt);
yeah i tried something similar yesterday: blkFormat= new QTextBlockFormat(); blkFormat->setBackground(QBrush(Qt::green,Qt::SolidPattern)); blkFormat->setForeground(QBrush(Qt::black,Qt::SolidPattern));textCursor().setBlockFormat(*blkFormat);So when I saw you using mergeBlockCharFormat() I figured that is what I was missing but I end up with the same result which is the program gets interrupted by the debugger:
yan bellavance
2010-03-25 16:25:56