summaryrefslogtreecommitdiffstats
path: root/examples/pdfwidgets/pdfviewer/doc/src/pdfviewer.qdoc
blob: 64b453be90840750092955776e62e7246ebca156 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \example pdfviewer
    \ingroup qtpdf-examples

    \title PDF Viewer Example
    \brief A widget-based PDF viewer that allows scrolling through the pages.

    \omit
    //! TODO add thumbnail \image pdfviewer.png
    \endomit

    \e {PDF Viewer} demonstrates how to use the QPdfView class to render
    PDF documents and the QPdfPageNavigator class to navigate them.

    Qt Creator and the integrated Qt Designer were used to create the example
    UI and to connect it to the code. This affects the code, which might be
    somewhat different to what you would typically write by hand.
    For more information about using Qt Designer, see \l{Qt Designer Manual}
    and \l{Qt Creator: Creating a Qt Widget Based Application}.

    \include examples-run.qdocinc

    \section1 Creating the Main Window

    The MainWindow class inherits the QMainWindow class:

    \quotefromfile pdfviewer/mainwindow.h
    \skipto public
    \printuntil ~MainWindow()

    The class declares public and private slots that match the actions of the
    selectors:

    \printuntil on_actionForward_triggered()

    The actual layout of the main window is specified in a \c{.ui} file. The
    widgets and actions are available at runtime in the \c ui member variable.

    \printuntil Ui::

    The \c m_zoomSelector variable holds the zoom selector and the
    \c m_pageSelector holds the page selector. The \c m_document
    variable is an instance of the QPdfDocument class that contains
    the PDF document.

    \printuntil }

    The actual setup of the different objects is done in the MainWindow
    constructor:

    \quotefromfile pdfviewer/mainwindow.cpp
    \skipto MainWindow
    \printuntil {

    The constructor first calls \c setupUi() to construct most of the main window
    according to the UI file. The zoom and page selectors need to be added to
    the toolbar via \l QToolBar::insertWidget(), because that cannot be done
    in a UI file:

    \printuntil insertWidget(ui->actionForward, m_pageSelector);

    We connect relevant signals to the page selector spinbox and the browser-style
    back and forward buttons:

    \printuntil forwardAvailableChanged

    We connect the \c zoomModeChanged and \c zoomFactor changed signals of the
    PDF view to the functions that reset the zoom selector:

    \printuntil reset()

    We then load the PDF document to the viewer:

    \dots
    \skipto pdfView
    \printuntil ;

    Finally, we connect the \c zoomFactorChanged signal to the function that
    sets the value of the zoom selector:

    \printuntil }

    \section1 Files and Attributions
*/