Print QPixmap
-
Hello,
I would like to print a pixmap to a pdf file and via QPrintDialog also on paper. However, I have a problem, every time the pixmap prints as a very small image. How can I enlarge it to a full page up to A4?QPixmap pixmap = this->grab(); QPrinter printer(QPrinter::HighResolution); printer.setPageMargins(QMarginsF(0,0,0,0)); QPainter painter; painter.begin(&printer); painter.drawPixmap (0, 0, pixmap.scaled(600, 800)); painter.end(); QPrintDialog dialog(&printer); dialog.exec();
-
Please take a look into the documentation on how to scale a pixmap so it fits to your page.
-
https://doc.qt.io/qt-5/qprinter.html#setPageSize
try to create a svg file for scaling. You can easily lose resolution with image for scaling. -
Ok, but I have the following errors now
-
https://doc.qt.io/qt-5/qprinter.html#paperRect-1 you need unit
-
@JoeCFD said in Print QPixmap:
https://doc.qt.io/qt-5/qprinter.html#paperRect-1 you need unit
No, pageRect() without a unit was deprecated in Qt5 and removed in Qt6 but the documentation here was not adjusted (will do asap). The deprecation documentation tells how to replace it:
"Use pageLayout().fullRectPixels(resolution()) instead."
-
Ok, I made it with this code
I got the pdf scaled to the page as I wanted, thank you for your help!
-
Christian Ehrlicher Lifetime Qt Championreplied to Piotrek102 on last edited by Christian Ehrlicher
@Piotrek102 Thx for the information, the Qt6 documentation will be updated shortly. Please mark the topic as solved then.
/gerrit commit for reference: https://codereview.qt-project.org/c/qt/qtbase/+/421268