File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -370,6 +370,7 @@ void MainWindow::print_action() {
370370 QRectF paint_rect = layout.paintRect (QPageLayout::Point);
371371 QSize pointsize = pagesize.sizePoints ();
372372 qreal ratio = scene_rect.width () / scene_rect.height ();
373+ // Cut off the excess
373374 if (paint_rect.height () * ratio > paint_rect.width ()) {
374375 pointsize.setHeight (
375376 pointsize.height () - paint_rect.height () + paint_rect.width () / ratio);
@@ -383,6 +384,12 @@ void MainWindow::print_action() {
383384 }
384385
385386 QPainter painter (&printer);
387+ // scale to fit paint size
388+ QRectF paint_rect = printer.pageLayout ().paintRect (QPageLayout::Millimeter);
389+ double xscale = paint_rect.width () / scene_as_vector.widthMM ();
390+ double yscale = paint_rect.height () / scene_as_vector.heightMM ();
391+ double scale = qMin (xscale, yscale);
392+ painter.scale (scale, scale);
386393 painter.drawPicture (0 , 0 , scene_as_vector);
387394 painter.end ();
388395 }
You can’t perform that action at this time.
0 commit comments