QPixmap pixmapToPrint
= window
->GetImageGraphicsView
()->PaintToPixmap
();
QSize size
= pixmapToPrint
->size
();
QRect viewport
= painter.
viewport();
qDebug() << "pixmap size: " << size; // output: QSize(382,393)
qDebug() << "painter viewport: " << viewport; // output: QRect(0,0 4958x7016)
size.scale(viewport.size(), Qt::KeepAspectRatio);
painter.setViewport(viewport.x(),viewport.y(),size.width(),size.height());
painter.setWindow(pixmapToPrint->rect());
qDebug() << "corrected painter viewport: " << painter.viewport(); // output: QRect(0,0 4958x5100)
qDebug() << "corrected painter window: " << painter.window(); // output: QRect(0,0 382x393)
painter.drawPixmap(0,0,*pixmapToPrint);
QPixmap pixmapToPrint = window->GetImageGraphicsView()->PaintToPixmap();
QPainter painter(GetPrinter());
QSize size = pixmapToPrint->size();
QRect viewport = painter.viewport();
qDebug() << "pixmap size: " << size; // output: QSize(382,393)
qDebug() << "painter viewport: " << viewport; // output: QRect(0,0 4958x7016)
size.scale(viewport.size(), Qt::KeepAspectRatio);
painter.setViewport(viewport.x(),viewport.y(),size.width(),size.height());
painter.setWindow(pixmapToPrint->rect());
qDebug() << "corrected painter viewport: " << painter.viewport(); // output: QRect(0,0 4958x5100)
qDebug() << "corrected painter window: " << painter.window(); // output: QRect(0,0 382x393)
painter.drawPixmap(0,0,*pixmapToPrint);
To copy to clipboard, switch view to plain text mode
Bookmarks