no simple way to print a QTextDocument in KDE(?)

Andreas Hartmetz ahartmetz at gmail.com
Wed Jul 25 01:40:57 BST 2007


Hi!

Today I tried to fix the printing functionality in KNotes which didn't
quite work right after porting. I felt a bit too smart when I saw that
I could trash ~70% of the old code and do this:

...QTextDocument texDoc;
KPrinter printer;
printer.setup(...);
textDoc.print(&printer);

-but-
KPrinter doesn't inherit QPrinter! Noooo!

As you can see by looking at the implementation of
QTextDocument::print(), it's not exactly trivial to implement rich
text printing *correctly*. KNotes has what looks like a half baked
(&using Q3Support (*) ) version of said implementation which,
incidentally, also didn't fully survive porting between KDE and Qt
versions. Its output became partly broken.
Turns out that KPrinter not inheriting QPrinter sucks...
I think that printing support from QTextDocument can make the
difference between smallish applications getting printing support or
not. It's two orders of magnitude easier and less error prone than the
manual way.
Can somebody familiar with the matter think of a solution that works
now, or how much stuff would need to be changed to make it work?
One solution might be a KTextDocument that just reimplements print(),
for example. Or KPrinter::printTextDocument() [...]

(*)Q3Support probably isn't perfect either, but I really couldn't
blame Trolltech for not making a transitional library perfect.

Cheers,
Andreas




More information about the kde-core-devel mailing list