PDA

View Full Version : Change margin on QTextEdit print()



Dii
19th May 2008, 10:36
Hi!

I might be dumb, but can't figure out this... :(
So I have a nice QTextEdit... I want to print it, as in the big book:


QPrinter printer;
printer.setPageSize (QPrinter::A4); printer.setFullPage (true);
QPrintDialog *dialog = new QPrintDialog (&printer, this);
if (dialog->exec() != QDialog::Accepted) return;
print (&printer);

I see it in the PDF file, it looks fine, but the margin is too big. Looks like the setFullPage(true) does nothing. I tried several stuff, a few to notice:

Change the document's margin and print that one:
http://trolltech.com/developer/knowledgebase/faq.2008-01-17.5101025464/

Change printengine properity:
printer.printEngine()->setProperty(QPrintEngine::PPK_PaperRect, rect1);

If I try to print with the QPainter engine, it's fine and full page, just it's rather painful to work out with the painter.... and couldn't find a way to send the QTextEdit to painter.

Does anyone have any idea?

patrik08
19th May 2008, 12:54
Take http://doc.trolltech.com/4.1/qtextdocument.html from qtextedit

xdoc = edit->document();

and send this to dialog;
http://www.qt-apps.org/content/show.php/TextPrinter?content=62383



TextPrinter *textprinter_ = new TextPrinter(this);
textprinter_->setHeaderSize(0);
textprinter_->setLeftMargin(12);
textprinter_->setRightMargin(10);
textprinter_->setHeaderText(tr("Foo date %1").arg(QDateTime::currentDateTime().toString()));
textprinter_->preview(xdoc, tr("Preview xx"));

Dii
20th May 2008, 22:45
I just found out that the new version of Qt (4.4.0) contains some improvements regarding the margin handling:

"Made a number of improvements to printing in Qt 4.4, including support for setting custom page sizes and custom margins ... "

Textprinter is also fine...

Thank you for your help!