[Interest] Print Preview with different page orientations in one document

Petric Frank pfrank at gmx.de
Wed Nov 2 13:32:28 CET 2022


Hello,

i try to print a document mixed Portait/Landscape pages.

Platform ist Linux
Qt is at version 5.15.5

The first page should be shown in portait, the second in landscape. But here
all pages are shown in landscape.
The preview always uses the same page height (here: the one of landscape).

When output to printer or PDF everything is ok.

Do i miss something ?

The basic code is:
------------------ cut --------------------
void MainWindow::doPrintPreview ()
{
  QPrinter printer (QPrinter::HighResolution);
  printer.setPageOrientation (QPageLayout::Portrait);
  QPrintPreviewDialog preview (&printer, this);

  connect (&preview, &QPrintPreviewDialog::paintRequested, this, [=] (QPrinter
* printer) { printView (printer); });

  preview.exec ();
}

void MainWindow::printView (QPrinter * printer)
{
  QPainter painter (printer);
  QGraphicsScene * scene;

  printer->setPageOrientation (QPageLayout::Portrait);

  // output the first page
  scene = ... // create and fill the scene
  scene->render (&painter, ...

  printer->setPageOrientation (QPageLayout::Landscape);
  printer->newPage ();

  // output the second page
  scene = ... // create and fill the scene
  scene->render (&painter, ...
}
------------------ cut --------------------

Maybe this is a general limitation of the QPrintPreviewDialog class, but i
haven't seen this limit in the documentation.

Any hints for me ?

kind regards
  Petric




More information about the Interest mailing list