- Qt 6.12
- Qt PDF
- C++ Classes
- QPdfView
- Qt 6.12.0 Reference Documentation

# QPdfView Class

A PDF viewer widget. More...

Header: | `#include <qpdfview.h>`
Inherits: | QAbstractScrollArea

- List of all members, including inherited members

## Public Types

enum class | PageMode { SinglePage, MultiPage }
enum class | ZoomMode { Custom, FitToWidth, FitInView }

## Properties

`(since 6.6)` currentSearchResultIndex : int document : QPdfDocument* documentMargins : QMargins pageMode : PageMode | pageSpacing : int `(since 6.6)` searchModel : QPdfSearchModel* zoomFactor : qreal zoomMode : ZoomMode

## Public Functions

| QPdfView(QWidget *parent)
virtual | ~QPdfView()
int | currentSearchResultIndex() const
QPdfDocument * | document() const
QMargins | documentMargins() const
QPdfView::PageMode | pageMode() const
QPdfPageNavigator * | pageNavigator() const
int | pageSpacing() const
QPdfSearchModel * | searchModel() const
void | setDocument(QPdfDocument *document)
void | setDocumentMargins(QMargins margins)
void | setPageSpacing(int spacing)
void | setSearchModel(QPdfSearchModel *searchModel)
qreal | zoomFactor() const
QPdfView::ZoomMode | zoomMode() const

## Public Slots

void | setCurrentSearchResultIndex(int currentResult)
void | setPageMode(QPdfView::PageMode mode)
void | setZoomFactor(qreal factor)
void | setZoomMode(QPdfView::ZoomMode mode)

## Signals

void | currentSearchResultIndexChanged(int currentResult)
void | documentChanged(QPdfDocument *document)
void | documentMarginsChanged(QMargins documentMargins)
void | pageModeChanged(QPdfView::PageMode pageMode)
void | pageSpacingChanged(int pageSpacing)
void | searchModelChanged(QPdfSearchModel *searchModel)
void | zoomFactorChanged(qreal zoomFactor)
void | zoomModeChanged(QPdfView::ZoomMode zoomMode)

## Detailed Description

QPdfView is a PDF viewer widget that offers a user experience similar to many common PDF viewer applications, with two modes. In the `MultiPage` mode, it supports flicking through the pages in the entire document, with narrow gaps between the page images. In the `SinglePage` mode, it shows one page at a time.

## Member Type Documentation

### enum class QPdfView::PageMode

This enum describes the overall behavior of the PDF viewer:

Constant | Value | Description
--- | --- | ---
`QPdfView::PageMode::SinglePage` | `0` | Show one page at a time.
`QPdfView::PageMode::MultiPage` | `1` | Allow scrolling through all pages in the document.

### enum class QPdfView::ZoomMode

This enum describes the magnification behavior of the PDF viewer:

Constant | Value | Description
--- | --- | ---
`QPdfView::ZoomMode::Custom` | `0` | Use zoomFactor only.
`QPdfView::ZoomMode::FitToWidth` | `1` | Automatically choose a zoom factor so that the width of the page fits in the view.
`QPdfView::ZoomMode::FitInView` | `2` | Automatically choose a zoom factor so that the entire page fits in the view.

## Property Documentation

### `[since 6.6]` currentSearchResultIndex : int

If this property is set to a positive number, and searchModel is set, QPdfView draws a frame around the search result provided by QPdfSearchModel at the given index. For example, if QPdfSearchModel is used as the model for a QListView, you can keep this property updated by connecting QItemSelectionModel::currentChanged() from QListView::selectionModel() to a function that will in turn call this function.

By default it is `-1`, so that no search results are framed.

This enumeration was introduced in Qt 6.6.

Access functions:

int | currentSearchResultIndex() const
void | setCurrentSearchResultIndex(int currentResult)

Notifier signal:

void | currentSearchResultIndexChanged(int currentResult)

### document : QPdfDocument*

This property holds the document to be viewed.

Access functions:

QPdfDocument * | document() const
void | setDocument(QPdfDocument *document)

Notifier signal:

void | documentChanged(QPdfDocument *document)

### documentMargins : QMargins

This property holds the margins around the page view.

Access functions:

QMargins | documentMargins() const
void | setDocumentMargins(QMargins margins)

Notifier signal:

void | documentMarginsChanged(QMargins documentMargins)

### pageMode : PageMode

This property holds whether to show one page at a time, or all pages in the document. The default is `SinglePage`.

Access functions:

QPdfView::PageMode | pageMode() const
void | setPageMode(QPdfView::PageMode mode)

Notifier signal:

void | pageModeChanged(QPdfView::PageMode pageMode)

### pageSpacing : int

This property holds the size of the padding between pages in the MultiPage mode.

Access functions:

int | pageSpacing() const
void | setPageSpacing(int spacing)

Notifier signal:

void | pageSpacingChanged(int pageSpacing)

### `[since 6.6]` searchModel : QPdfSearchModel*

If this property is set, QPdfView draws highlight rectangles over the search results provided by QPdfSearchModel::resultsOnPage(). By default it is `nullptr`.

This enumeration was introduced in Qt 6.6.

Access functions:

QPdfSearchModel * | searchModel() const
void | setSearchModel(QPdfSearchModel *searchModel)

Notifier signal:

void | searchModelChanged(QPdfSearchModel *searchModel)

### zoomFactor : qreal

This property holds the ratio of pixels to points. The default is `1`, meaning one point (1/72 of an inch) equals 1 logical pixel.

Access functions:

qreal | zoomFactor() const
void | setZoomFactor(qreal factor)

Notifier signal:

void | zoomFactorChanged(qreal zoomFactor)

### zoomMode : ZoomMode

This property indicates whether to use a custom size for the page(s), or zoom them to fit to the view. The default is `CustomZoom`.

Access functions:

QPdfView::ZoomMode | zoomMode() const
void | setZoomMode(QPdfView::ZoomMode mode)

Notifier signal:

void | zoomModeChanged(QPdfView::ZoomMode zoomMode)

## Member Function Documentation

### `[explicit]` QPdfView::QPdfView(QWidget *parent)

Constructs a PDF viewer with parent widget parent.

### `[virtual noexcept]` QPdfView::~QPdfView()

Destroys the PDF viewer.

### QPdfPageNavigator *QPdfView::pageNavigator() const

This accessor returns the navigation stack that will handle back/forward navigation.