Results 1 to 9 of 9

Thread: Printing a pixmap full page: strange behavior on Windows

  1. #1
    Join Date
    Jan 2006
    Location
    Genk, Belgium
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Printing a pixmap full page: strange behavior on Windows

    In my application I print a pixmap, full page. Under Linux this works fine, but on Windows, only part of the pixmap is printed, with a high zoom-in level.

    In attachment, both pdfs.

    The printing code fragment:

    Qt Code:
    1. QPixmap pixmapToPrint = window->GetImageGraphicsView()->PaintToPixmap();
    2. QPainter painter(GetPrinter());
    3. QSize size = pixmapToPrint->size();
    4. QRect viewport = painter.viewport();
    5.  
    6. qDebug() << "pixmap size: " << size; // output: QSize(382,393)
    7. qDebug() << "painter viewport: " << viewport; // output: QRect(0,0 4958x7016)
    8.  
    9. size.scale(viewport.size(), Qt::KeepAspectRatio);
    10. painter.setViewport(viewport.x(),viewport.y(),size.width(),size.height());
    11. painter.setWindow(pixmapToPrint->rect());
    12.  
    13. qDebug() << "corrected painter viewport: " << painter.viewport(); // output: QRect(0,0 4958x5100)
    14. qDebug() << "corrected painter window: " << painter.window(); // output: QRect(0,0 382x393)
    15.  
    16. painter.drawPixmap(0,0,*pixmapToPrint);
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  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: Printing a pixmap full page: strange behavior on Windows

    Does GetPrinter() include setting up the printer?

  3. #3
    Join Date
    Jan 2006
    Location
    Genk, Belgium
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing a pixmap full page: strange behavior on Windows

    GetPrinter() returns an instance variable created when first needed using

    Qt Code:
    1. mpPrinter = new QPrinter(QPrinter::PrinterResolution);
    To copy to clipboard, switch view to plain text mode 

    And configurated using a QPrintDialog:

    Qt Code:
    1. QPrintDialog setupPrinterDialog(GetPrinter(),this);
    2. if (setupPrinterDialog.exec())
    3. {
    4. [I]<<here the code mentioned earlier>>[/I]
    5. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Printing a pixmap full page: strange behavior on Windows

    I've got the same problem. Thought it relied on the printer. Hope now that anybody could help me.

  5. #5
    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: Printing a pixmap full page: strange behavior on Windows

    Are you sure this is correct?

    Qt Code:
    1. painter.drawPixmap(0,0,*pixmapToPrint);
    To copy to clipboard, switch view to plain text mode 

    It shouldn't even compile...

  6. #6
    Join Date
    Jan 2006
    Location
    Genk, Belgium
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: Printing a pixmap full page: strange behavior on Windows

    I'm sorry. I distilled the code fragment from the actual code, leaving out irrelevant elements, and changed a pointer to a pixmap into a pixmap, but not in a consequent manner.

    Should have been:

    Qt Code:
    1. painter.drawPixmap(0,0,pixmapToPrint);
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Sep 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Printing a pixmap full page: strange behavior on Windows

    My Code is similar to the code in the Image Viewer example:
    QPrinter *printer = new QPrinter(QPrinter::HighResolution);
    QPrintDialog dialog(printer, this);

    printer->setOrientation(QPrinter::Landscape);

    if (dialog.exec()) {
    QPainter painter(printer);
    QRect rect = painter.viewport();
    QSize size = diagram->imageLabel->pixmap()->size();

    size.scale(rect.size(), Qt::KeepAspectRatio);
    painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
    painter.setWindow(diagram->imageLabel->pixmap()->rect());
    painter.drawPixmap(0, 0, *diagram->imageLabel->pixmap());
    }

    I have to say, that the Imageviewer example has the same problem after I installed QT4.3.0. With QT 4.1.1 the example and my code worked.

  8. #8
    Join Date
    Sep 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Printing a pixmap full page: strange behavior on Windows

    After installation of the new Qt version 4.3.2 it worked again.

  9. #9
    Join Date
    Jan 2006
    Location
    Genk, Belgium
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing a pixmap full page: strange behavior on Windows

    Some time ago I've found what the problem is:
    I used the deprecated QPrinter::PrinterResolution printer mode, which has been documented to behave in a non-portable way. I've changed it to QPrinter::HighResolution and everything works fine.

    Thanks for your ideas.

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.