Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
widgetprinting.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QtWidgets>
5#include <QtPrintSupport/qtprintsupportglobal.h>
6#if QT_CONFIG(printdialog)
7#include <QPrinter>
8#include <QPrintDialog>
9#endif
10
11class Window : public QWidget
12{
14
15public:
17 {
18 myWidget = new QPushButton("Print Me");
20 myWidget2 = new QPushButton("Print Document");
22 editor = new QTextEdit(this);
23
29 }
30
31private slots:
32 void print()
33 {
34 #if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
36
37 printer.setOutputFileName("test.pdf");
38
39//! [0]
42 const auto pageLayout = printer.pageLayout();
45 double xscale = pageRect.width() / double(myWidget->width());
46 double yscale = pageRect.height() / double(myWidget->height());
47 double scale = qMin(xscale, yscale);
49 pageRect.y() + paperRect.height() / 2.);
51 painter.translate(-myWidget->width() / 2., -myWidget->height() / 2.);
52
54//! [0]
55 #endif
56 }
57
58 void printFile()
59 {
60 #if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
61//! [1]
63
65 dialog.setWindowTitle(tr("Print Document"));
68 if (dialog.exec() != QDialog::Accepted)
69 return;
70//! [1]
72 #endif
73 }
74
75private:
77 QPushButton *myWidget2;
78 QTextEdit *editor;
79};
80
81#include "main.moc"
82
83int main(int argv, char **args)
84{
85 QApplication app(argv, args);
86
87 Window window;
88 window.show();
89
90 return app.exec();
91}
[Window class with invokable method]
Definition window.h:11
int main(int argc, char *argv[])
[ctor_close]