Simply creating a document in colour
-
Hi all, I’m afraid I’m still quite new to Qt and C++ and would like some advice. I have my program that uses fstream to create a text file. It all works great. Now I want to create the same document but the text needs to be in colour. I’ve read up about QTextDocument but I’m hoping that someone can point me in the direction of a simple example to help me understand it better.
Many Thanks
Chris -
VCsala - I’m looking to print it, I dont need to view it - actually I’m looking to save it - pdf, rtf would be fine. When the document prints it needs to print in 4 colours.
Gerolf - Fantastic, I think I need to be working along the QTextDocument lines. Rich Text would work and would be able to Print out and save with coloured text (happy to save in rich text format - that would be ideal).
Unfortunately, I’m really stupid and I cant work out the code to save a simple rtf file. I have all the data in memory, it is just a case of knowing how to save it. If anyone can point me in the direction of some example code, I would be very grateful.
Thanks for your speedy replies. You’re very kind.
-
You can use QTextDocumentWriter to output a QTextDocument to a supported format.
Unfortunately, QTextDocument does not support RTF as an output format. Only plain text, HTML and ODF are supported. I did not find an easy way to add support for a format either, though I might have just overlooked this in the documentation. The API design seems to have been done in a way that this should be possible though.
-
Yes, ODF supports colored text. I am, however, not 100% positive that QTextDocumentWriter supports that feature of ODF, but that would be a simple test to make yourself, would it not?
The documentation of QTextDocumentWriter is quite clear, and the interface quite simple, I think. Is there anything in there you don't understand specifically?
-
-
[quote author="Gerolf" date="1301914256"]I just had a look at the code of QTextEdit which (per documentation) also accepts RichText format, built only for user input (drag and drop, copy/paste) :-(
SO I'm afraid, only plaintext, odf or html is possible (without extra coding)[/quote]
That might actually warrant a feature request: add RTF to the list of supported formats for QTextDocumentWriter, and make it possible to add custom formats for that. -
OK, fair enough:
- "Make list of supported QTextDocumentWriter formats extendible":http://bugreports.qt.nokia.com/browse/QTBUG-18570
- "Add support for RTF to QTextDocumentWriter":http://bugreports.qt.nokia.com/browse/QTBUG-18571