Results 1 to 20 of 32

Thread: QPrinter & QPainter render() problem

Hybrid View

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

    Default QPrinter & QPainter render() problem

    I have a problem when calling Qwidget::render() on a specific printer connected via a network to a PC running XP. I am quite new to using the Qprinter class so I apologise if I am missing something obvious. I get a repeatable crash when rendering to the printer in question. The only diffreence I can see between the working printers and the crashing one is the printer resolution. I seem to get the problem no matter what I render. The crash always seesm to occur at the render() call.

    Here is attached example code:

    Qt Code:
    1. void MainWindow::menuPrintTest(){
    2. double xscale; double yscale; double scale;
    3. double printerWidth ; double printerHeight ;
    4. double widgetWidth; double widgetHeight ;
    5. QFont printFont("courier", 16);
    6. printFont.setFixedPitch(TRUE);
    7. QTextEdit *qteTestPrintRequest = new QTextEdit("",w);
    8. qteTestPrintRequest ->setFont(printFont );
    9. qteTestPrintRequest ->setFixedHeight(1750);
    10. qteTestPrintRequest ->setFixedWidth(1050);
    11. widgetWidth = qteTestPrintRequest ->width();
    12. widgetHeight = qteTestPrintRequest ->height();
    13.  
    14. QString qsConcat = "Test Printout For Checking XP Print Request Bug\n";
    15. for (int i=0; i<30; i++){ qsConcat+= "Test Printout for Checking XP Print Request Bug\n" ; }
    16. qteTestPrintRequest->append( qsConcat );
    17.  
    18. QPrinter printer(QPrinter::HighResolution);
    19. QString docName = "Test Plot";
    20. if ( !docName.isEmpty()) {
    21. docName.replace (QRegExp (QString::fromLatin1 ("\n")), tr (" -- "));
    22. printer.setDocName (docName);
    23. }
    24. QPrintDialog dialog(&printer);
    25. if ( dialog.exec() ) {
    26. {
    27. {
    28. QPainter painter(&printer);
    29. printerWidth = printer.pageRect().width();
    30. printerHeight = printer.pageRect().height();
    31. xscale = printerWidth/(widgetWidth);
    32. yscale = printerHeight/(widgetHeight);
    33. scale = qMin(xscale, yscale);
    34. painter.scale(scale, scale);
    35. qteTestPrintRequest ->render(&painter);
    36. }
    37. }
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 





    The qDebug() output for the scaling is as follows:

    printerWidth = 4908.0
    printerHeight = 6408.0
    widgetWidth = 1050.0
    widgetHeight = 1750.0
    xscale = 4.674
    yscale = 3.662
    scale = 3.662

    As a matter of interest the output on one of the working printers is

    printerWidth = 4760.0
    printerHeight = 6814.0
    widgetWidth = 1050.0
    widgetHeight = 1750.0
    xscale = 4.533
    yscale = 3.894
    scale = 3.894

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPrinter & QPainter render() problem

    Try printing something small - does it still crash then?
    Also, you have a memory leak - you never delete 'qteTestPrintRequest' (but that should not play a role in the problem you have).
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Default Re: QPrinter & QPainter render() problem

    Thankyou

    I will try a print that is well within the pageRect() dimensions.

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

    Default Re: QPrinter & QPainter render() problem

    I don't want to duplicate effort. My great thanks to all who have helped so far.

    I hope that this is helpful to all concerned but this thread is being discussed in more detail on this link.

    http://www.qtforum.org/article/37518...tml#post117656

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

    Default Re: QPrinter & QPainter render() problem

    "I do need to rsolve this ASAP and would be willing to pay for a solution/resolution.":http://www.qtforum.org/article/37518...tml#post117656

    The code above seems to work perfectly with all other configurations of Printer & PC tested. The problem seems to be that my simple test printout is generating a huge print document approximately a factor of 4000 times bigger (e.g. 213MB for a single A4 sheet) when sent to the specific printer involved:

    Xerox Work Centre 7428 PS

    The only potential leads I have are that it may be due to

    1. A specific printer driver issue

    2. QPrinter printer(QPrinter::HighResolution);
    A guess.

    3. qteTestPrintRequest->render(&painter);
    Using render with a QTextEdit widget instead of using qteTestPrintRequest ->print(&printer);

    4. Some other unidentified issue with the code posted above?
    Last edited by Mannion; 11th March 2012 at 19:47.

  6. #6
    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 & QPainter render() problem

    Maybe you should bother to answer high_flyer's question from post #2?
    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.


Similar Threads

  1. QPainter(&QPrinter) & QPainter(&QImage) communication
    By gufeatza in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2010, 07:25
  2. QPainter bug or QPrinter bug?
    By lni in forum Qt Programming
    Replies: 6
    Last Post: 30th March 2009, 01:48
  3. How to render the contents of QPrinter to QWidget
    By nifei in forum Qt Programming
    Replies: 0
    Last Post: 6th March 2009, 04:25
  4. QPainter & QPrinter on linux (fedora 7)
    By wbt_ph in forum Qt Programming
    Replies: 4
    Last Post: 20th October 2007, 15:37
  5. QPainter & QPrinter
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2006, 14:19

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.