Using QPrintPreviewWidget to preview pages with different orientation or paper ?
-
Hi !
I search for information but found nothing about how to preview a set of pages, some of which are portrait while others ar landscape. If I change the QPrintPreviewWidget orientation while in the slot, the orientation is not changed and remains what it was at the first call.
Here is the part of the code which is a simple test to print something on many pages with some portrait and some landscape. Note that what is being print by that example is not important. Focus on the if statement.
@void MainWindow::print2Slot(QPrinter *printer)
{
QPixmap image("C:/Users/DELL_02/Desktop/image.png");QPainter painterPrinter(printer); qreal x = 0; qreal y = 0; for (int iPage = 0; iPage < 5; iPage++) { if ((iPage % 2) == 0) printer->setOrientation(QPrinter::Portrait); else printer->setOrientation(QPrinter::Landscape); x = iPage * 100.0 * printer->resolution() / 90; y = iPage * 100.0 * printer->resolution() / 90; QRectF rectangleS(x, y, 100, 100); painterPrinter.drawImage(rectangleS, image.toImage(), rectangleS); if (iPage < 4) printer->newPage(); }
}
@Thank you !
-
I don't see the code using a QPrintPreviewWidget.
Maybe you need to refactor it so that the QPainter object is constructed with the QPainter after the orientation is changed?
-
Hi !
What you see in the code is the slot being called when the QPrintPreviewWidget emit a signal for update.
The problem has been adressed but not really solved since I learn from Digia that changing paper orientation while in preview is not yet supported. It is however a feature requested but there is no timeframe for that futur feature !!!
The only workaround is to build one page at a time, ensuring that the printer is properly set for the right orientation and then use QPrintPreviewWidget to show this page.
Thank you !