Results 1 to 6 of 6

Thread: Printing and Paper Geometry

  1. #1
    Join Date
    Feb 2007
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Printing and Paper Geometry

    I'm trying to figure out the paper geometry when I print. I'm going for letter size paper, but if I print a box to the paper rectangle or to the page rectangle, the boxes are too big. When I print out the sizes from the QPrinter object, they're way out of wack too. This seems to be the case for two trypes of printers (HP PhotoSmart and HP OfficeJet) and any of the paper sizes.

    Here's what I get when I query the QPrinter object for letter size paper with the OfficeJet:


    logical DPI X: 98, logical DPI Y: 98
    physical DPI X: 1200, physical DPI Y: 1200

    device Width: 784
    device Height: 1017

    device Width in inches (width / 25.4): 30.8661
    device height in inches (height / 25.4): 40.0394

    device Width in mm: 784
    device height in mm: 1017

    Page Rect width: 784 height: 1017
    top left: 25,12, top right: 808,12
    bottom left: 25,1028, bottom right: 808,1028

    Paper Rect width: 833 height: 1078
    top left: 0,0, top right: 832,0
    bottom left: 0,1077, bottom right: 832,1077

  2. #2
    Join Date
    Feb 2007
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing and Paper Geometry

    As a second note, the first example was using Linux. I have since run the same program on Windows and get similar results.

    Any idea of what I may be doing wrong, or is Qt busted when it comes to printers?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing and Paper Geometry

    Qt Code:
    1. #include <QApplication>
    2. #include <QPrintDialog>
    3. #include <QPrinter>
    4.  
    5. #include <QtDebug>
    6.  
    7. int main( int argc, char ** argv )
    8. {
    9. QApplication app( argc, argv );
    10.  
    11. QPrintDialog pd( &p );
    12. pd.exec();
    13.  
    14. QRect pr = p.paperRect();
    15. double r = p.resolution();
    16.  
    17. qDebug() << "QPrinter:";
    18. qDebug() << "paper =" << pr;
    19. qDebug() << "page =" << p.pageRect();
    20. qDebug() << "res. =" << r;
    21. qDebug() << "inSize =" << pr.width() / r << "x" << pr.height() / r;
    22.  
    23. qDebug() << "QPaintDevice:";
    24. qDebug() << "pDpi =" << p.physicalDpiX() << "x" << p.physicalDpiY();
    25. qDebug() << "lDpi =" << p.logicalDpiX() << "x" << p.logicalDpiY();
    26. qDebug() << "size =" << p.width() << "x" << p.height();
    27. qDebug() << "mmSize =" << p.widthMM() << "x" << p.heightMM();
    28.  
    29. return 0;
    30. }
    To copy to clipboard, switch view to plain text mode 

    The results:

    Xerox Phaser (A4):
    $ ./printer
    QPrinter:
    paper = QRect(0,0 735x1041)
    page = QRect(17,17 701x1006)
    res. = 89
    inSize = 8.25843 x 11.6966
    QPaintDevice:
    pDpi = 1200 x 1200
    lDpi = 89 x 89
    size = 701 x 1006
    mmSize = 200 x 287
    Xerox Phaser (Letter):
    $ ./printer
    QPrinter:
    paper = QRect(0,0 757x979)
    page = QRect(17,17 722x944)
    res. = 89
    inSize = 8.50562 x 11
    QPaintDevice:
    pDpi = 1200 x 1200
    lDpi = 89 x 89
    size = 722 x 944
    mmSize = 206 x 269
    Xerox WorkCentre (Letter):
    $ ./printer
    QPrinter:
    paper = QRect(0,0 757x979)
    page = QRect(15,15 728x951)
    res. = 89
    inSize = 8.50562 x 11
    QPaintDevice:
    pDpi = 1200 x 1200
    lDpi = 89 x 89
    size = 728 x 951
    mmSize = 208 x 271
    So everything seems to be OK (I have Qt 4.3.2).

    Edit: The same on Qt 4.3.3.
    Last edited by jacek; 19th December 2007 at 16:24.

  4. #4
    Join Date
    Feb 2007
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing and Paper Geometry

    Can you do me a favor and add the following lines of code and tell me if the rectangles show on the paper? For me they don't. I only see the left and bottom of the page rectangle and the left side of the paper rectangle.


    QPainter painter(&p);
    painter.drawRect(p.pageRect());
    painter.setPen(QPen(QColor("blue")));
    painter.drawRect(pr);

    Thanks

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing and Paper Geometry

    I've managed to print the page rectange using following code:
    Qt Code:
    1. painter.translate( -p.pageRect().topLeft() );
    2. painter.drawRect( p.pageRect().adjusted( 1, 0, 0, -1 ) );
    To copy to clipboard, switch view to plain text mode 

    The first line is needed because:
    The rectangle returned by pageRect() usually lies inside the rectangle returned by paperRect(). You do not need to take the positions and sizes of these area into account when using a QPainter with a QPrinter as the underlying paint device; the origin of the painter's coordinate system will coincide with the top-left corner of the page rectangle, and painting operations will be clipped to the bounds of the drawable part of the page.
    (It's from Printing with Qt.)

    The call to adjusted() just corrects some rounding errors which aren't necessarily Qt's fault.

  6. #6
    Join Date
    Feb 2007
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing and Paper Geometry

    Thanks, the call to translate got me a lot closer. I still have to adjust it by 5 or more for the one printer, but like I said, it's a lot closer. Maybe this is why they have such large margins on the built in printing of the html documents.

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.