Qt6 Printing in Landscape
-
This code was working in Qt5:
#include <QApplication> #include <QPrinter> #include <QPainter> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPrinter printer; printer.setPageOrientation(QPageLayout::Landscape); QPainter painter(&printer); painter.drawText(100, 100, "¡Hola, mundo!, ¿que tal estan ustedes?"); painter.end(); return 0; }
I mean that having an A4 loaded in the printer in a potrait position, the system rotated the printout to show it in landscape format. This code in Qt6 does not rotate the text and prints it outside the margin, the same thing happens using PageLayout which seems the right direction for Qt6:
#include <QApplication> #include <QPrinter> #include <QPainter> #include <QPageLayout> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPrinter printer; QPageLayout pageLayout = printer.pageLayout(); pageLayout.setOrientation(QPageLayout::Landscape); printer.setPageLayout(pageLayout); QPainter painter(&printer); painter.drawText(100, 100, "¡Hola, mundo!, ¿qué tal están ustedes?"); painter.end(); return 0; }
How should we maintain this functionality, without resorting to manual rotation?
By the way, if print to a PDF printer it works fine in all cases and my Qt is 6.4.2 running in ubuntu.
-
Hi and welcome to devnet,
It looks like it could be a regression. Can you test with a more recent version of Qt ? The current series is 6.7 with 6.8 around the corner.