Results 1 to 3 of 3

Thread: what unit is used in QTextDocument::setPageSize() method?

  1. #1
    Join Date
    Sep 2009
    Posts
    9
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Unhappy what unit is used in QTextDocument::setPageSize() method?

    My program involve printing to a roll script which is just 8 cm width. I have set the paper size of the QPrinter accordingly. The content is rendered from a QTextDocument object. The output was cropped on the right side. Hence I would like to set the page size on the QTextDocument in order to render the content correctly. The problem is, what unit is used in the QTextDocument::setPageSize method?

    Here is my code snip.
    Qt Code:
    1. QTextDocument *lpDocument(ui.mpTextEditPrintOut->document());
    2. QPrinter lrPrinter;
    3.  
    4. QPrintDialog* lpDlg(new QPrintDialog(&lrPrinter, this));
    5. lrPrinter.setPaperSize(QSizeF(8.0, 10.0), QPrinter::Millimeter);
    6. lrPrinter.setPageMargins(0.0, 0.0, 0.0, 0.0, QPrinter::Millimeter);
    7. if (lpDlg->exec() != QDialog::Accepted)
    8. {
    9. return;
    10. }
    11.  
    12. lpDocument->print(&lrPrinter);
    To copy to clipboard, switch view to plain text mode 

    development environment:
    Qt 4.4.0.
    MSVC 8.0 SP1 with Qt Visual Studio Integration 1.4.0.
    Win XP SP3.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: what unit is used in QTextDocument::setPageSize() method?

    I think you meant:
    Qt Code:
    1. lrPrinter.setPaperSize(QSizeF(80, 100), QPrinter::Millimeter);
    To copy to clipboard, switch view to plain text mode 

    If you look at the mergins after this:
    Qt Code:
    1. lrPrinter.setPageMargins(0.0, 0.0, 0.0, 0.0, QPrinter::Millimeter);
    To copy to clipboard, switch view to plain text mode 
    you might find they are not zero and shifting your output to the right. Something similar to this is happening to me on Windows (http://www.qtcentre.org/forum/f-qt-p...ffs-23771.html), where even
    Qt Code:
    1. setFullPage(true);
    To copy to clipboard, switch view to plain text mode 
    does not seem to help.

    Does it look correct if you output to PDF?

  3. #3
    Join Date
    Jun 2012
    Location
    Austria
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: what unit is used in QTextDocument::setPageSize() method?

    The unit for QTextDocument is point (pt).

    Qt Code:
    1. const qreal PT_MM = 25.4/72.0;
    2. document.setDocumentMargin(20.0/PT_MM); // sets margin to 20mm
    To copy to clipboard, switch view to plain text mode 
    It also works with html images:
    Qt Code:
    1. document.setHtml("<img src=\"anyimg.jpg\" width = 200 />); // creates an image 200pt = 200*PT_MM millimeters wide
    To copy to clipboard, switch view to plain text mode 

    To set a PageSize use:

    Qt Code:
    1. QSizeF size = printer.paperSize(QPrinter::Point);
    2. document.setPageSize(size);
    To copy to clipboard, switch view to plain text mode 
    Last edited by gsoral; 3rd June 2012 at 16:39. Reason: missing [code] tags

Similar Threads

  1. Drawing a widget in QItemDelegate's paint method
    By darkadept in forum Qt Programming
    Replies: 17
    Last Post: 11th August 2009, 06:15
  2. Creating object of other class in Run() method
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 16:05
  3. Calling Recursivly loading function in Run() method of QThread
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 15:42
  4. Replies: 4
    Last Post: 10th March 2007, 19:01
  5. variable in method not initialized?!
    By frosch in forum Qt Programming
    Replies: 10
    Last Post: 3rd September 2006, 15:09

Tags for this Thread

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.