Results 1 to 4 of 4

Thread: QTextDocument: print or drawContents?

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTextDocument: print or drawContents?

    I would like to understand which is the difference between print() and drawContenst() methods of QTextDocument.
    I know that print() can handle page breaking while drawContents not.
    So far, I have been using drawContents() because I can handle easily complex layout.
    However, if I have to put in the TextDocument a complex html I use
    document->setHtml(string).
    But: when I use drawContents(&painter,printer->paperRect())
    I get always a very small and unreadable square of printed text on the output pages.

    If I use a transformation like:
    Qt Code:
    1. document->adjustSize();
    2. QTransform tra;
    3. tra.scale(11,11);
    4. painter.setTransform(tra);
    To copy to clipboard, switch view to plain text mode 

    the page is visible. Why shall I use the transofmration?
    Is there a method to set a transformation independent of the printer device?
    Thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextDocument: print or drawContents?

    You have to remember that your printer has a different resolution than your screen. If your screen has 96dpi and your printer has 1200dpi, the difference is roughly 11 times which would explain the figures. You need to use QPrinter and QPrintDialog methods to initialize the printer paint device properly.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextDocument: print or drawContents?

    I use one class for printing on pdf and QPrintPreview to print on other devices.
    Printing on pdf is ok, no problem, all pages are correctly handled, both on windows and linux.
    But when I run the app on windows, the preview printing does not work perfectly. I mean, margins are sometimes different.
    However, I use QPainter painter(printer), i.e. the painter is initialized with the printer.
    And, if I debug. I obtain:
    painter.viewport().width() = printer.pageRect().width()

    p.s. what I am talking about is this http://bugreports.qt.nokia.com/browse/QTBUG-3290

    G
    Last edited by giusepped; 12th November 2009 at 02:08.

  4. #4

    Default Re: QTextDocument: print or drawContents?

    Hello everyone,

    Althought this is an old thread, i post my solution took me a few hours...
    By default the document is painting with qt::screenresolution and event scaling this to the right size the painting quality on paper is ugly(draft).
    But using the code :

    QPrinter printer(QPrinter::HighResolution);
    QPainter painter(&printer);
    QTexDocument doc;
    doc.documentLayout()->setPaintDevice(painter.device());
    doc.setHtml("htmlcontent");
    doc.drawContents(painter);

Similar Threads

  1. Trouble to print with QPrintPreviewWidget
    By estanisgeyer in forum Qt Programming
    Replies: 5
    Last Post: 24th December 2009, 06:14
  2. print preview
    By wbt_ph in forum Qt Programming
    Replies: 4
    Last Post: 1st August 2009, 06:41
  3. Insert SVG inside QTextDocument
    By giusepped in forum Qt Programming
    Replies: 6
    Last Post: 23rd April 2009, 19:57
  4. Print of QTextDocument
    By tsschulz in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2008, 10:18
  5. Replies: 0
    Last Post: 28th June 2006, 20:49

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.