QPrintPreviewDialog Class

The QPrintPreviewDialog class provides a dialog for previewing and configuring page layouts for printer output. More...

Header: #include <QPrintPreviewDialog>
CMake: find_package(Qt6 COMPONENTS PrintSupport REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::PrintSupport)
qmake: QT += printsupport
Inherits: QDialog

Public Functions

QPrintPreviewDialog(QPrinter *printer, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
QPrintPreviewDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
virtual ~QPrintPreviewDialog()
void open(QObject *receiver, const char *member)
QPrinter *printer()

Reimplemented Public Functions

virtual void done(int result) override
virtual void setVisible(bool visible) override

Signals

void paintRequested(QPrinter *printer)

Detailed Description

Using QPrintPreviewDialog in your existing application is straightforward:

  1. Create the QPrintPreviewDialog.

    You can construct a QPrintPreviewDialog with an existing QPrinter object, or you can have QPrintPreviewDialog create one for you, which will be the system default printer.

  2. Connect the paintRequested() signal to a slot.

    When the dialog needs to generate a set of preview pages, the paintRequested() signal will be emitted. You can use the exact same code for the actual printing as for having the preview generated, including calling QPrinter::newPage() to start a new page in the preview. Connect a slot to the paintRequested() signal, where you draw onto the QPrinter object that is passed into the slot.

  3. Call exec().

    Call QPrintPreviewDialog::exec() to show the preview dialog.

See also QPrinter, QPrintDialog, QPageSetupDialog, and QPrintPreviewWidget.

Member Function Documentation

QPrintPreviewDialog::QPrintPreviewDialog(QPrinter *printer, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

Constructs a QPrintPreviewDialog based on printer and with parent as the parent widget. The widget flags flags are passed on to the QWidget constructor.

See also QWidget::setWindowFlags().

QPrintPreviewDialog::QPrintPreviewDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

This is an overloaded function.

This will create an internal QPrinter object, which will use the system default printer.

[signal] void QPrintPreviewDialog::paintRequested(QPrinter *printer)

This signal is emitted when the QPrintPreviewDialog needs to generate a set of preview pages.

The printer instance supplied is the paint device onto which you should paint the contents of each page, using the QPrinter instance in the same way as you would when printing directly.

[virtual] QPrintPreviewDialog::~QPrintPreviewDialog()

Destroys the QPrintPreviewDialog.

[override virtual] void QPrintPreviewDialog::done(int result)

Reimplements: QDialog::done(int r).

void QPrintPreviewDialog::open(QObject *receiver, const char *member)

This is an overloaded function.

Opens the dialog and connects its finished(int) signal to the slot specified by receiver and member.

The signal will be disconnected from the slot when the dialog is closed.

QPrinter *QPrintPreviewDialog::printer()

Returns a pointer to the QPrinter object this dialog is currently operating on.

[override virtual] void QPrintPreviewDialog::setVisible(bool visible)

Reimplements: QDialog::setVisible(bool visible).

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.