JAN
27
2008

Building a QTextDocument the hard way...

So now I am trying to put the output of my wiki parser into a QTextDocument. I am struggling with the QTextCursor though. Things are not acting at all as I would think they do. I think its because I am constantly using insertHtml() everywhere still...

So I'm calling out to any QTextDocument gurus for a bit of help. I am sure its because I have not been working with the QTextDocument an entire 3 hours now, but I for the life of me cannot get a horizontal rule inserted into my document without using insertHtml("<hr>"); This is acceptable, but for some reason my document then has a horizontal rule after every paragraph in my document. If i replace "<hr>" with "---" i see the correct output. The next problem I seem to be stuck with is how do I append a block, edit said block and then go past the end of it so that I can create a new block with none of the prior formatting?

These things seem pretty trivial, so I am not worried. I will more than likely figure them out in the next few days. I just wish there was more documentation and sample code on how to build up a QTextDocument block by block.

Other than that things are moving along pretty well. I even am as far as round tripping basic text and headings from Creole 1.0 wiki format to a QTextDocument, and then back to the wiki format.

Comments

I suggest you read the KWDLoader.cpp file (in koffice/kword/part) which uses QTextCursor solely to insert text into a document.

ps. your above problem can be solved by using QTextCursor::insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat);


By Thomas Zander at Mon, 01/28/2008 - 12:19

Ah, so I have to reset the format after i insert the html. How might I do this without a block insert?

Meanwhile I am going to have a look at the KWord source.


By Ian Reinhart Geiser at Mon, 01/28/2008 - 21:40