QPrinter printer(QPrinter::HighResolution);printer.setPageSize(QPrinter::A4);QPrintDialog printDialog(&printer, this);QPainter painter(&printer);QRect rect = painter.viewport();QSize size(590,840); size.scale(rect.size(), Qt::KeepAspectRatio); painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); painter.setWindow(0,0,590,840); painter.setRenderHint(QPainter::SmoothPixmapTransform, true);painter.begin(); QImage img; img.load("test.jpg");img = img.scaled(520,450, Qt::KeepAspectRatio, Qt::SmoothTransformation);painter.drawImage(0, 0, img);painter.end();
QPrinter printer(QPrinter::HighResolution);printer.setPageSize(QPrinter::A4);QPrintDialog printDialog(&printer, this);QPainter painter(&printer);QRect rect = painter.viewport();QSize size(590,840); size.scale(rect.size(), Qt::KeepAspectRatio); painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); painter.setWindow(0,0,590,840); //<<<<<<qDebug() << "Viewport:" << painter.viewport();// <<<<<<painter.setRenderHint(QPainter::SmoothPixmapTransform, true);painter.begin(); QImage img; img.load("test.jpg");img = img.scaled(520,450, Qt::KeepAspectRatio, Qt::SmoothTransformation);painter.drawImage(0, 0, img);painter.end();