Preview & Scaling in Printer Dialog
-
Hi,
AFAIR, on macOS, it's the system dialog that is shown so you should have your OS standard feature in there.
-
Hi,
AFAIR, on macOS, it's the system dialog that is shown so you should have your OS standard feature in there.
-
@SGaist That is what I thought also, but it does not appear.
I get hat you can see below. It is missing the Preview, Auto-Rotate and "Fit to Size" Options. -
@ademmler it seems that you will have to implement you own
-
@ademmler it seems that you will have to implement you own
@Ronel_qtmaster Yes maybe - but still laundering, because the first image I have send is MacNative Dialog.
I check further into this. -
@Ronel_qtmaster Yes maybe - but still laundering, because the first image I have send is MacNative Dialog.
I check further into this. -
@ademmler Can you provide a minimal compilable example so that we can check things on the same level ?
@SGaist Sure - I have put both Dialogs into one example - you can choose which one to use at the top of main.cpp.
#include <QApplication> #include <QPrinter> #include <QPrintDialog> #include <QPrintPreviewDialog> #include <QPainter> #define usePreview 0 class MyPrintPreviewDialog : public QPrintPreviewDialog { public: MyPrintPreviewDialog(QPrinter *printer, QWidget *parent = nullptr) : QPrintPreviewDialog(printer, parent) { // Connect the signal for generating the preview connect(this, &QPrintPreviewDialog::paintRequested, this, &MyPrintPreviewDialog::printPreview); } private: void printPreview(QPrinter *printer) { // Create a QPainter to draw on the printer QPainter painter(printer); // Draw some text on the printer painter.drawText(QRect(20, 20, 200, 200), "Hello, World!"); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); #if usePreview // Create a printer object QPrinter printer; // Create a print preview dialog MyPrintPreviewDialog dialog(&printer); // Show the print preview dialog dialog.exec(); #else // Create a printer object QPrinter printer; printer.setPageSize(QPrinter::A4); printer.setOrientation(QPrinter::Portrait); printer.setResolution(300); // Create a print dialog and get print settings from the user QPrintDialog printDialog(&printer); if (printDialog.exec() != QDialog::Accepted) { return 0; // User canceled the print dialog } // Create a QPainter object and set it to draw on the printer QPainter painter(&printer); // Use the QPainter to draw on the printer painter.drawText(QRect(100, 100, 200, 200), "Hello, World!"); painter.drawLine(QPointF(0, 0), QPointF(100, 100)); // ... // End the painting and release the printer painter.end(); #endif return app.exec(); }
QtCreator project file:
###################################################################### # Automatically generated by qmake (3.1) Tue Feb 13 09:33:07 2024 ###################################################################### QT += core gui network printsupport TEMPLATE = app TARGET = trial INCLUDEPATH += . # Input SOURCES += main.cpp
-
@SGaist Sure - I have put both Dialogs into one example - you can choose which one to use at the top of main.cpp.
#include <QApplication> #include <QPrinter> #include <QPrintDialog> #include <QPrintPreviewDialog> #include <QPainter> #define usePreview 0 class MyPrintPreviewDialog : public QPrintPreviewDialog { public: MyPrintPreviewDialog(QPrinter *printer, QWidget *parent = nullptr) : QPrintPreviewDialog(printer, parent) { // Connect the signal for generating the preview connect(this, &QPrintPreviewDialog::paintRequested, this, &MyPrintPreviewDialog::printPreview); } private: void printPreview(QPrinter *printer) { // Create a QPainter to draw on the printer QPainter painter(printer); // Draw some text on the printer painter.drawText(QRect(20, 20, 200, 200), "Hello, World!"); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); #if usePreview // Create a printer object QPrinter printer; // Create a print preview dialog MyPrintPreviewDialog dialog(&printer); // Show the print preview dialog dialog.exec(); #else // Create a printer object QPrinter printer; printer.setPageSize(QPrinter::A4); printer.setOrientation(QPrinter::Portrait); printer.setResolution(300); // Create a print dialog and get print settings from the user QPrintDialog printDialog(&printer); if (printDialog.exec() != QDialog::Accepted) { return 0; // User canceled the print dialog } // Create a QPainter object and set it to draw on the printer QPainter painter(&printer); // Use the QPainter to draw on the printer painter.drawText(QRect(100, 100, 200, 200), "Hello, World!"); painter.drawLine(QPointF(0, 0), QPointF(100, 100)); // ... // End the painting and release the printer painter.end(); #endif return app.exec(); }
QtCreator project file:
###################################################################### # Automatically generated by qmake (3.1) Tue Feb 13 09:33:07 2024 ###################################################################### QT += core gui network printsupport TEMPLATE = app TARGET = trial INCLUDEPATH += . # Input SOURCES += main.cpp
The preview dialog is indeed non-native but the setup part is.
As for having the preview in the print dialog, you would have to modify the backend part to set it up.
-
The preview dialog is indeed non-native but the setup part is.
As for having the preview in the print dialog, you would have to modify the backend part to set it up.
-
@SGaist Thx for checking this out. Do I understand you right - did you ment to take the default QPrinter class and add more "setup functionality" aka native code to get the OS related preview activated?