Results 1 to 3 of 3

Thread: Change margin on QTextEdit print()

  1. #1
    Join Date
    Mar 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Change margin on QTextEdit print()

    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:

    Qt Code:
    1. QPrinter printer;
    2. printer.setPageSize (QPrinter::A4); printer.setFullPage (true);
    3. QPrintDialog *dialog = new QPrintDialog (&printer, this);
    4. if (dialog->exec() != QDialog::Accepted) return;
    5. print (&printer);
    To copy to clipboard, switch view to plain text mode 

    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/knowl...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?

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change margin on QTextEdit print()

    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....?content=62383

    Qt Code:
    1. TextPrinter *textprinter_ = new TextPrinter(this);
    2. textprinter_->setHeaderSize(0);
    3. textprinter_->setLeftMargin(12);
    4. textprinter_->setRightMargin(10);
    5. textprinter_->setHeaderText(tr("Foo date %1").arg(QDateTime::currentDateTime().toString()));
    6. textprinter_->preview(xdoc, tr("Preview xx"));
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to patrik08 for this useful post:

    gordebak (25th May 2010)

  4. #3
    Join Date
    Mar 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Change margin on QTextEdit print()

    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!

Similar Threads

  1. Replies: 2
    Last Post: 9th March 2007, 23:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.