Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qprintpreviewdialog.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6#include <private/qprinter_p.h>
7#include "qprintdialog.h"
8
9#include <QtGui/qaction.h>
10#include <QtGui/qactiongroup.h>
11#include <QtWidgets/qboxlayout.h>
12#include <QtWidgets/qcombobox.h>
13#include <QtWidgets/qlineedit.h>
14#include <QtPrintSupport/qpagesetupdialog.h>
15#include <QtPrintSupport/qprinter.h>
16#include <QtWidgets/qstyle.h>
17#include <QtWidgets/qtoolbutton.h>
18#include <QtGui/qvalidator.h>
19#if QT_CONFIG(filedialog)
20#include <QtWidgets/qfiledialog.h>
21#endif
22#include <QtWidgets/qmainwindow.h>
23#include <QtWidgets/qtoolbar.h>
24#include <QtCore/QCoreApplication>
25
26#include "private/qdialog_p.h"
27
28#include <QtWidgets/qformlayout.h>
29#include <QtWidgets/qlabel.h>
30
31#include <QtCore/qpointer.h>
32
34{
35 static bool resourcesInitialized = false;
36 if (!resourcesInitialized) {
37 Q_INIT_RESOURCE(qprintdialog);
38 resourcesInitialized = true;
39 }
40}
41
43
44using namespace Qt::StringLiterals;
45
46namespace {
47class QPrintPreviewMainWindow : public QMainWindow
48{
49public:
50 QPrintPreviewMainWindow(QWidget *parent) : QMainWindow(parent) {}
51 QMenu *createPopupMenu() override { return nullptr; }
52};
53
54class ZoomFactorValidator : public QDoubleValidator
55{
56public:
57 ZoomFactorValidator(QObject* parent)
58 : QDoubleValidator(parent) {}
59 ZoomFactorValidator(qreal bottom, qreal top, int decimals, QObject *parent)
60 : QDoubleValidator(bottom, top, decimals, parent) {}
61
62 State validate(QString &input, int &pos) const override
63 {
64 bool replacePercent = false;
65 if (input.endsWith(u'%')) {
66 input = input.left(input.size() - 1);
67 replacePercent = true;
68 }
70 if (replacePercent)
71 input += u'%';
72 const int num_size = 4;
73 if (state == Intermediate) {
74 int i = input.indexOf(QLocale::system().decimalPoint());
75 if ((i == -1 && input.size() > num_size)
76 || (i != -1 && i > num_size))
77 return Invalid;
78 }
79 return state;
80 }
81};
82
83class LineEdit : public QLineEdit
84{
86public:
87 LineEdit(QWidget* parent = nullptr)
88 : QLineEdit(parent)
89 {
90 setContextMenuPolicy(Qt::NoContextMenu);
91 connect(this, &LineEdit::returnPressed, this, &LineEdit::handleReturnPressed);
92 }
93
94protected:
95 void focusInEvent(QFocusEvent *e) override
96 {
97 origText = text();
99 }
100
101 void focusOutEvent(QFocusEvent *e) override
102 {
103 if (isModified() && !hasAcceptableInput())
104 setText(origText);
106 }
107
108private slots:
109 void handleReturnPressed()
110 {
111 origText = text();
112 }
113
114private:
115 QString origText;
116};
117} // anonymous namespace
118
120{
121 Q_DECLARE_PUBLIC(QPrintPreviewDialog)
122public:
126
127 // private slots
128 void _q_fit(QAction *action);
129 void _q_zoomIn();
130 void _q_zoomOut();
131 void _q_navigate(QAction *action);
132 void _q_setMode(QAction *action);
133 void _q_pageNumEdited();
134 void _q_print();
135 void _q_pageSetup();
136 void _q_previewChanged();
138
139 void init(QPrinter *printer = nullptr);
142 void setupActions();
143 void updateNavActions();
144 void setFitting(bool on);
145 bool isFitting();
146 void updatePageNumLabel();
147 void updateZoomFactor();
148
155
156 // widgets:
160
161 // actions:
167
171
175
179
184
188
191};
192
194{
196
198
199 if (_printer) {
200 preview = new QPrintPreviewWidget(_printer, q);
201 printer = _printer;
202 } else {
203 ownPrinter = true;
204 printer = new QPrinter;
206 }
207 QObject::connect(preview, SIGNAL(paintRequested(QPrinter*)), q, SIGNAL(paintRequested(QPrinter*)));
208 QObject::connect(preview, SIGNAL(previewChanged()), q, SLOT(_q_previewChanged()));
209 setupActions();
210
211 pageNumEdit = new LineEdit;
214 pageNumLabel = new QLabel;
215 QObject::connect(pageNumEdit, SIGNAL(editingFinished()), q, SLOT(_q_pageNumEdited()));
216
217 zoomFactor = new QComboBox;
218 zoomFactor->setEditable(true);
221 LineEdit *zoomEditor = new LineEdit;
222 zoomEditor->setValidator(new ZoomFactorValidator(1, 1000, 1, zoomEditor));
223 zoomFactor->setLineEdit(zoomEditor);
224 static const short factorsX2[] = { 25, 50, 100, 200, 250, 300, 400, 800, 1600 };
225 for (auto factorX2 : factorsX2)
226 zoomFactor->addItem(QPrintPreviewDialog::tr("%1%").arg(factorX2 / 2.0));
227 QObject::connect(zoomFactor->lineEdit(), SIGNAL(editingFinished()),
229 QObject::connect(zoomFactor, SIGNAL(currentIndexChanged(int)),
231
232 QPrintPreviewMainWindow *mw = new QPrintPreviewMainWindow(q);
233 QToolBar *toolbar = new QToolBar(mw);
234 toolbar->addAction(fitWidthAction);
235 toolbar->addAction(fitPageAction);
236 toolbar->addSeparator();
237 toolbar->addWidget(zoomFactor);
238 toolbar->addAction(zoomOutAction);
239 toolbar->addAction(zoomInAction);
240 toolbar->addSeparator();
241 toolbar->addAction(portraitAction);
242 toolbar->addAction(landscapeAction);
243 toolbar->addSeparator();
244 toolbar->addAction(firstPageAction);
245 toolbar->addAction(prevPageAction);
246
247 // this is to ensure the label text and the editor text are
248 // aligned in all styles - the extra QVBoxLayout is a workaround
249 // for bug in QFormLayout
250 QWidget *pageEdit = new QWidget(toolbar);
251 QVBoxLayout *vboxLayout = new QVBoxLayout;
252 vboxLayout->setContentsMargins(0, 0, 0, 0);
253#ifdef Q_OS_MAC
254 // We query the widgets about their size and then we fix the size.
255 // This should do the trick for the laying out part...
256 QSize pageNumEditSize, pageNumLabelSize;
257 pageNumEditSize = pageNumEdit->minimumSizeHint();
258 pageNumLabelSize = pageNumLabel->minimumSizeHint();
259 pageNumEdit->resize(pageNumEditSize);
260 pageNumLabel->resize(pageNumLabelSize);
261#endif
263#ifdef Q_OS_MAC
264 // We have to change the growth policy in Mac.
266#endif
269 vboxLayout->addLayout(formLayout);
270 vboxLayout->setAlignment(Qt::AlignVCenter);
271 pageEdit->setLayout(vboxLayout);
272 toolbar->addWidget(pageEdit);
273
274 toolbar->addAction(nextPageAction);
275 toolbar->addAction(lastPageAction);
276 toolbar->addSeparator();
277 toolbar->addAction(singleModeAction);
278 toolbar->addAction(facingModeAction);
280 toolbar->addSeparator();
281 toolbar->addAction(pageSetupAction);
282 toolbar->addAction(printAction);
283
284 // Cannot use the actions' triggered signal here, since it doesn't autorepeat
285 QToolButton *zoomInButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomInAction));
286 QToolButton *zoomOutButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomOutAction));
287 zoomInButton->setAutoRepeat(true);
288 zoomInButton->setAutoRepeatInterval(200);
289 zoomInButton->setAutoRepeatDelay(200);
290 zoomOutButton->setAutoRepeat(true);
291 zoomOutButton->setAutoRepeatInterval(200);
292 zoomOutButton->setAutoRepeatDelay(200);
293 QObject::connect(zoomInButton, SIGNAL(clicked()), q, SLOT(_q_zoomIn()));
294 QObject::connect(zoomOutButton, SIGNAL(clicked()), q, SLOT(_q_zoomOut()));
295
296 mw->addToolBar(toolbar);
297 mw->setCentralWidget(preview);
298 // QMainWindows are always created as top levels, force it to be a
299 // plain widget
300 mw->setParent(q, Qt::Widget);
301
302 QVBoxLayout *topLayout = new QVBoxLayout;
303 topLayout->addWidget(mw);
304 topLayout->setContentsMargins(0, 0, 0, 0);
305 q->setLayout(topLayout);
306
307 QString caption = QCoreApplication::translate("QPrintPreviewDialog", "Print Preview");
308 if (!printer->docName().isEmpty())
309 caption += ": "_L1 + printer->docName();
310 q->setWindowTitle(caption);
311
312 if (!printer->isValid()
313#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
315#endif
316 )
318 preview->setFocus();
319}
320
322{
323 const auto imagePrefix = ":/qt-project.org/dialogs/qprintpreviewdialog/images/"_L1;
325 icon.addFile(imagePrefix + name + "-24.png"_L1, QSize(24, 24));
326 icon.addFile(imagePrefix + name + "-32.png"_L1, QSize(32, 32));
327 action->setIcon(icon);
328}
329
331{
333
334 // Navigation
335 navGroup = new QActionGroup(q);
336 navGroup->setExclusive(false);
337 nextPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Next page"));
338 prevPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Previous page"));
339 firstPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "First page"));
340 lastPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Last page"));
341 qt_setupActionIcon(nextPageAction, "go-next"_L1);
342 qt_setupActionIcon(prevPageAction, "go-previous"_L1);
343 qt_setupActionIcon(firstPageAction, "go-first"_L1);
344 qt_setupActionIcon(lastPageAction, "go-last"_L1);
346
347
348 fitGroup = new QActionGroup(q);
349 fitWidthAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit width"));
350 fitPageAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit page"));
351 fitWidthAction->setObjectName("fitWidthAction"_L1);
352 fitPageAction->setObjectName("fitPageAction"_L1);
355 qt_setupActionIcon(fitWidthAction, "zoom-fit-width"_L1);
356 qt_setupActionIcon(fitPageAction, "zoom-fit-page"_L1);
358
359 // Zoom
360 zoomGroup = new QActionGroup(q);
361 zoomInAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom in"));
362 zoomOutAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom out"));
363 qt_setupActionIcon(zoomInAction, "zoom-in"_L1);
364 qt_setupActionIcon(zoomOutAction, "zoom-out"_L1);
365
366 // Portrait/Landscape
368 portraitAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Portrait"));
369 landscapeAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Landscape"));
372 qt_setupActionIcon(portraitAction, "layout-portrait"_L1);
373 qt_setupActionIcon(landscapeAction, "layout-landscape"_L1);
374 QObject::connect(portraitAction, SIGNAL(triggered(bool)), preview, SLOT(setPortraitOrientation()));
375 QObject::connect(landscapeAction, SIGNAL(triggered(bool)), preview, SLOT(setLandscapeOrientation()));
376
377 // Display mode
378 modeGroup = new QActionGroup(q);
379 singleModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show single page"));
380 facingModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show facing pages"));
381 overviewModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show overview of all pages"));
382 qt_setupActionIcon(singleModeAction, "view-pages-single"_L1);
383 qt_setupActionIcon(facingModeAction, "view-pages-facing"_L1);
384 qt_setupActionIcon(overviewModeAction, "view-pages-overview"_L1);
385 singleModeAction->setObjectName("singleModeAction"_L1);
386 facingModeAction->setObjectName("facingModeAction"_L1);
387 overviewModeAction->setObjectName("overviewModeAction"_L1);
388
393
394 // Print
396 printAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Print"));
397 pageSetupAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Page setup"));
398 qt_setupActionIcon(printAction, "printer"_L1);
399 qt_setupActionIcon(pageSetupAction, "page-setup"_L1);
400 QObject::connect(printAction, SIGNAL(triggered(bool)), q, SLOT(_q_print()));
402
403 // Initial state:
408 else
410}
411
412
418
419
421{
422 if (isFitting() == on)
423 return;
425 if (on) {
427 action->setChecked(true);
428 if (fitGroup->checkedAction() != action) {
429 // work around exclusitivity problem
430 fitGroup->removeAction(action);
431 fitGroup->addAction(action);
432 }
433 } else {
436 }
437}
438
440{
441 int curPage = preview->currentPage();
442 int numPages = preview->pageCount();
443 nextPageAction->setEnabled(curPage < numPages);
444 prevPageAction->setEnabled(curPage > 1);
445 firstPageAction->setEnabled(curPage > 1);
446 lastPageAction->setEnabled(curPage < numPages);
448}
449
451{
453
454 int numPages = preview->pageCount();
455 int maxChars = QString::number(numPages).size();
456 pageNumLabel->setText(QString::fromLatin1("/ %1").arg(numPages));
457 int cyphersWidth = q->fontMetrics().horizontalAdvance(QString().fill(u'8', maxChars));
458 int maxWidth = pageNumEdit->minimumSizeHint().width() + cyphersWidth;
459 pageNumEdit->setMinimumWidth(maxWidth);
460 pageNumEdit->setMaximumWidth(maxWidth);
462 // any old one will be deleted later along with its parent pageNumEdit
463}
464
469
471{
472 setFitting(true);
473 if (action == fitPageAction)
475 else
477}
478
485
492
494{
495 bool ok = false;
496 int res = pageNumEdit->text().toInt(&ok);
497 if (ok)
499}
500
502{
503 int curPage = preview->currentPage();
504 if (action == prevPageAction)
505 preview->setCurrentPage(curPage - 1);
506 else if (action == nextPageAction)
507 preview->setCurrentPage(curPage + 1);
508 else if (action == firstPageAction)
510 else if (action == lastPageAction)
513}
514
516{
517 if (action == overviewModeAction) {
519 setFitting(false);
520 fitGroup->setEnabled(false);
521 navGroup->setEnabled(false);
522 pageNumEdit->setEnabled(false);
523 pageNumLabel->setEnabled(false);
524 } else if (action == facingModeAction) {
526 } else {
528 }
529 if (action == facingModeAction || action == singleModeAction) {
530 fitGroup->setEnabled(true);
531 navGroup->setEnabled(true);
532 pageNumEdit->setEnabled(true);
534 setFitting(true);
535 }
536}
537
539{
541
542#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
544 QString title = QCoreApplication::translate("QPrintPreviewDialog", "Export to PDF");
545 QString suffix = ".pdf"_L1;
547#if QT_CONFIG(filedialog)
549#endif
550 if (!fileName.isEmpty()) {
551 if (QFileInfo(fileName).suffix().isEmpty())
552 fileName.append(suffix);
554 }
556 preview->print();
557 q->accept();
558 return;
559 }
560#endif
561
562 if (!printDialog)
565 preview->print();
566 q->accept();
567 }
568}
569
571{
573
574 if (!pageSetupDialog)
576
578 // update possible orientation changes
582 }else {
585 }
586 }
587}
588
595
597{
599 bool ok;
600 qreal factor = text.remove(u'%').toFloat(&ok);
601 factor = qMax(qreal(1.0), qMin(qreal(1000.0), factor));
602 if (ok) {
603 preview->setZoomFactor(factor/100.0);
605 setFitting(false);
606 }
607}
608
610
659{
661 d->init(printer);
662}
663
672 : QDialog(*new QPrintPreviewDialogPrivate, parent, f)
673{
675 d->init();
676}
677
682{
684 if (d->ownPrinter)
685 delete d->printer;
686 delete d->printDialog;
687 delete d->pageSetupDialog;
688}
689
694{
696 // this will make the dialog get a decent default size
697 if (visible && !d->initialized) {
698 d->preview->updatePreview();
699 d->initialized = true;
700 }
702}
703
708{
711 if (d->receiverToDisconnectOnClose) {
712 disconnect(this, SIGNAL(finished(int)),
713 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
714 d->receiverToDisconnectOnClose = nullptr;
715 }
716 d->memberToDisconnectOnClose.clear();
717}
718
728void QPrintPreviewDialog::open(QObject *receiver, const char *member)
729{
731 // the int parameter isn't very useful here; we could just as well connect
732 // to reject(), but this feels less robust somehow
733 connect(this, SIGNAL(finished(int)), receiver, member);
734 d->receiverToDisconnectOnClose = receiver;
735 d->memberToDisconnectOnClose = member;
737}
738
744{
746 return d->printer;
747}
748
762
763#include "moc_qprintpreviewdialog.cpp"
764#include "qprintpreviewdialog.moc"
The QActionGroup class groups actions together.
void setEnabled(bool)
QAction * checkedAction() const
Returns the currently checked action in the group, or \nullptr if none are checked.
void removeAction(QAction *a)
Removes the action from this group.
bool isExclusive() const
Returns true if the group is exclusive.
void setExclusive(bool)
Enable or disable the group exclusion checking.
QAction * addAction(QAction *a)
Adds the action to this group, and returns it.
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
void setChecked(bool)
Definition qaction.cpp:877
void setIcon(const QIcon &icon)
Definition qaction.cpp:547
void setEnabled(bool)
Definition qaction.cpp:927
void setCheckable(bool)
Definition qaction.cpp:832
bool isChecked() const
Definition qaction.cpp:892
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
\inmodule QtCore
Definition qbytearray.h:57
The QComboBox widget combines a button with a dropdown list.
Definition qcombobox.h:24
void setInsertPolicy(InsertPolicy policy)
QLineEdit * lineEdit() const
Returns the line edit used to edit items in the combobox, or \nullptr if there is no line edit.
void setMinimumContentsLength(int characters)
void addItem(const QString &text, const QVariant &userData=QVariant())
Adds an item to the combobox with the given text, and containing the specified userData (stored in th...
Definition qcombobox.h:209
void setEditText(const QString &text)
Sets the text in the combobox's text edit.
void setLineEdit(QLineEdit *edit)
Sets the line edit to use instead of the current line edit widget.
void setEditable(bool editable)
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
The QDialog class is the base class of dialog windows.
Definition qdialog.h:19
void finished(int result)
@ Accepted
Definition qdialog.h:30
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition qdialog.cpp:602
virtual void open()
Definition qdialog.cpp:503
void setVisible(bool visible) override
\reimp
Definition qdialog.cpp:744
The QDoubleValidator class provides range checking of floating-point numbers.
Definition qvalidator.h:89
QValidator::State validate(QString &, int &) const override
Returns \l Acceptable if the string input is in the correct format and contains a double within the v...
static QString getSaveFileName(QWidget *parent=nullptr, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=nullptr, Options options=Options())
This is a convenience static function that returns a file name selected by the user.
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
The QFormLayout class manages forms of input widgets and their associated labels.
Definition qformlayout.h:18
void setWidget(int row, ItemRole role, QWidget *widget)
Sets the widget in the given row for the given role to widget, extending the layout with empty rows i...
void setFieldGrowthPolicy(FieldGrowthPolicy policy)
@ AllNonFixedFieldsGrow
Definition qformlayout.h:36
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
void addFile(const QString &fileName, const QSize &size=QSize(), Mode mode=Normal, State state=Off)
Adds an image from the file with the given fileName to the icon, as a specialization for size,...
Definition qicon.cpp:1113
static QIcon fromTheme(const QString &name)
Definition qicon.cpp:1344
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
Definition qvalidator.h:56
The QLabel widget provides a text or image display.
Definition qlabel.h:20
void setText(const QString &)
Definition qlabel.cpp:263
QSize minimumSizeHint() const override
\reimp
Definition qlabel.cpp:831
void setContentsMargins(int left, int top, int right, int bottom)
Definition qlayout.cpp:288
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
QSize minimumSizeHint() const override
Returns a minimum size for the line edit.
void setValidator(const QValidator *)
Sets the validator for values of line edit to v.
void setAlignment(Qt::Alignment flag)
void focusOutEvent(QFocusEvent *) override
\reimp
void setText(const QString &)
QString text
The line edit's text.
Definition qlineedit.h:32
void focusInEvent(QFocusEvent *) override
\reimp
static QLocale system()
Returns a QLocale object initialized to the system locale.
Definition qlocale.cpp:2862
The QMainWindow class provides a main application window.
Definition qmainwindow.h:25
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:127
The QPageSetupDialog class provides a configuration dialog for the page-related options on a printer.
int exec() override
This virtual function is called to pop up the dialog.
The QPrintDialog class provides a dialog for specifying the printer's configuration.
int exec() override
\reimp
void init(QPrinter *printer=nullptr)
void _q_navigate(QAction *action)
QPointer< QObject > receiverToDisconnectOnClose
The QPrintPreviewDialog class provides a dialog for previewing and configuring page layouts for print...
~QPrintPreviewDialog()
Destroys the QPrintPreviewDialog.
QPrinter * printer()
Returns a pointer to the QPrinter object this dialog is currently operating on.
void done(int result) override
\reimp
QPrintPreviewDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setVisible(bool visible) override
\reimp
virtual void open()
Definition qdialog.cpp:503
The QPrintPreviewWidget class provides a widget for previewing page layouts for printer output.
int currentPage() const
Returns the currently viewed page in the preview.
void setPortraitOrientation()
This is a convenience function and is the same as calling {setOrientation(QPageLayout::Portrait)}.
void print()
Prints the preview to the printer associated with the preview.
void fitToWidth()
This is a convenience function and is the same as calling {setZoomMode(QPrintPreviewWidget::FitToWidt...
void zoomIn(qreal zoom=1.1)
Zooms the current view in by factor.
void setViewMode(ViewMode viewMode)
Sets the view mode to mode.
void zoomOut(qreal zoom=1.1)
Zooms the current view out by factor.
qreal zoomFactor() const
Returns the zoom factor of the view.
void setCurrentPage(int pageNumber)
Sets the current page in the preview.
void setLandscapeOrientation()
This is a convenience function and is the same as calling {setOrientation(QPageLayout::Landscape)}.
void fitInView()
This is a convenience function and is the same as calling {setZoomMode(QPrintPreviewWidget::FitInView...
void setZoomFactor(qreal zoomFactor)
Sets the zoom factor of the view to factor.
QPageLayout::Orientation orientation() const
Returns the current orientation of the preview.
\reentrant
Definition qprinter.h:28
@ NativeFormat
Definition qprinter.h:69
bool isValid() const
Definition qprinter.cpp:674
QString docName() const
Returns the document name.
Definition qprinter.cpp:772
QString outputFileName() const
Returns the name of the output file.
Definition qprinter.cpp:692
void setOutputFileName(const QString &)
Sets the name of the output file to fileName.
Definition qprinter.cpp:717
OutputFormat outputFormat() const
Definition qprinter.cpp:570
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
int toInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition qstring.h:731
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
float toFloat(bool *ok=nullptr) const
Returns the string converted to a float value.
Definition qstring.cpp:7950
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition qstring.cpp:3466
static QString static QString asprintf(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
Definition qstring.cpp:7263
The QToolBar class provides a movable panel that contains a set of controls.
Definition qtoolbar.h:23
QAction * addSeparator()
Adds a separator to the end of the toolbar.
Definition qtoolbar.cpp:755
QWidget * widgetForAction(QAction *action) const
QAction * addWidget(QWidget *widget)
Adds the given widget to the toolbar as the toolbar's last item.
Definition qtoolbar.cpp:792
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition qtoolbutton.h:20
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setSizePolicy(QSizePolicy)
void setMinimumWidth(int minw)
Definition qwidget.cpp:4112
void setEnabled(bool)
Definition qwidget.cpp:3358
void setFocus()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:423
void resize(int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:883
void setMaximumWidth(int maxw)
Definition qwidget.cpp:4130
bool visible
whether the widget is visible
Definition qwidget.h:144
QString text
else opt state
[0]
Combined button and popup list for selecting options.
@ AlignRight
Definition qnamespace.h:146
@ AlignVCenter
Definition qnamespace.h:155
@ Widget
Definition qnamespace.h:206
@ NoContextMenu
@ Invalid
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLdouble GLdouble GLdouble GLdouble top
GLfloat GLfloat f
GLint GLint bottom
GLbitfield flags
GLuint name
GLuint res
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLenum GLenum GLenum input
static void _q_ppd_initResources()
static void qt_setupActionIcon(QAction *action, QLatin1StringView name)
SSL_CTX int void * arg
#define Q_OBJECT
#define slots
#define Q_INIT_RESOURCE(name)
Definition qtresource.h:14
double qreal
Definition qtypes.h:187
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QObject::connect nullptr
QString title
[35]
myObject disconnect()
[26]
ba fill(true)
QFormLayout * formLayout
[0]
insertRed setText("insert red text")