Results 1 to 4 of 4

Thread: QPrinter - rectangle coordinates

  1. #1
    Join Date
    Mar 2012
    Posts
    1

    Default QPrinter - rectangle coordinates

    Hi. I have problem with printing rectangle with QPrinter on real device. Rectangle which I would like to draw is always cliped by a printer. Code below works great when it's export to PDF file.
    What I am doing wrong? Please help me. Without this simple task I can not finish my project.

    Qt Code:
    1. QPrinter printer;
    2. printer.setPageSize(QPrinter::A4);
    3. printer.setFullPage(true);
    4. // printer.setOutputFormat(QPrinter::PdfFormat);
    5. // printer.setOutputFileName("test.pdf");
    6.  
    7. QRectF rect = printer.pageRect();
    8.  
    9. double margin = rect.width()*0.05;
    10.  
    11. QRectF body = QRectF(margin, margin, rect.width()-margin*2, rect.height()-margin*2);
    12.  
    13. QPainter painter(&printer);
    14. painter.drawRect(body);
    15.  
    16. QTextOption option;
    17. option.setAlignment(Qt::AlignRight);
    18.  
    19. painter.drawText(body, "test right", option);
    20. painter.drawText(body, "test left");
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter - rectangle coordinates

    There doesn't look like anything glaringly wrong from my perspective. I would try looking at QPrinter margin settings

    void QPrinter::setPageMargins

    as there may be some potential conflict with

    void QPrinter::setFullPage

    and tweaking your calculated margin constant of 0.05 and seeing what happens to both the pdf and the printer output.

    If I wasn't working round the clock for a very crucial deadline I would spend longer on this issue. I will look back to see if I can find anything obvious.

    Good Luck

  3. #3
    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: QPrinter - rectangle coordinates

    Each printer has a margin where it can't print.
    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.


  4. #4
    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: QPrinter - rectangle coordinates

    There is at least one bug related to setFullPage() on Windows (if that is what you are using) also:
    https://bugreports.qt-project.org/browse/QTBUG-5363

    As far as I know it is still outstanding. This bug would cause clipping on the right and bottom of a full page sized box.

Similar Threads

  1. GPS coordinates via SMS
    By radeknati in forum Qt Programming
    Replies: 0
    Last Post: 20th April 2010, 12:56
  2. Replies: 4
    Last Post: 18th March 2010, 10:11
  3. Coordinates Related
    By jsmith in forum Qt Programming
    Replies: 0
    Last Post: 18th August 2009, 15:37
  4. getting mouse coordinates
    By eric in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 19:34
  5. QPrinter::PrinterMode and QPrinter::setResolution??
    By SkripT in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2006, 11:59

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.