On this page

QPdfSearchModel Class

The QPdfSearchModel class searches for a string in a PDF document and holds the results. More...

Header: #include <QPdfSearchModel>
Inherits: QAbstractListModel

Public Types

enum class Role { Page, IndexOnPage, Location, ContextBefore, ContextAfter }
(since 6.12) enum class Status { Null, Searching, Finished }

Properties

Public Functions

QPdfSearchModel(QObject *parent)
virtual ~QPdfSearchModel() override
int count() const
QPdfDocument *document() const
QPdfLink resultAtIndex(int index) const
QList<QPdfLink> resultsOnPage(int page) const
QString searchString() const
QPdfSearchModel::Status status() const

Reimplemented Public Functions

virtual QVariant data(const QModelIndex &index, int role) const override
virtual QHash<int, QByteArray> roleNames() const override
virtual int rowCount(const QModelIndex &parent) const override

Public Slots

void setDocument(QPdfDocument *document)
void setSearchString(const QString &searchString)

Signals

void countChanged()
void documentChanged()
void searchStringChanged()
void statusChanged(QPdfSearchModel::Status status)

Detailed Description

This is used in the Model/View Programming paradigm to display a list of search results, to highlight them on the rendered PDF pages, and to iterate through them using the "search forward" / "search backward" buttons and shortcuts that would be found in a typical document-viewing UI:

Member Type Documentation

enum class QPdfSearchModel::Role

ConstantValueDescription
QPdfSearchModel::Role::PageQt::UserRoleThe page number where the search result is found (int).
QPdfSearchModel::Role::IndexOnPage257The index of the search result on the page (int).
QPdfSearchModel::Role::Location258The position of the search result on the page (QPointF).
QPdfSearchModel::Role::ContextBefore259The adjacent text on the page, before the search string (QString).
QPdfSearchModel::Role::ContextAfter260The adjacent text on the page, after the search string (QString).

See also QPdfLink.

[since 6.12] enum class QPdfSearchModel::Status

This enum describes the current status of the search model.

ConstantValueDescription
QPdfSearchModel::Status::Null0The initial status before the first search has begun.
QPdfSearchModel::Status::Searching1The status while the search is being conducted.
QPdfSearchModel::Status::Finished2The status when all possible search results have been found on all pages.

This enum was introduced in Qt 6.12.

See also QPdfSearchModel::status().

Property Documentation

[read-only, since 6.8] count : int

This property holds the number of search results found

This property was introduced in Qt 6.8.

Access functions:

int count() const

Notifier signal:

void countChanged()

document : QPdfDocument*

This property holds the document to search

Access functions:

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

Notifier signal:

void documentChanged()

searchString : QString

This property holds the string to search for

Access functions:

QString searchString() const
void setSearchString(const QString &searchString)

Notifier signal:

void searchStringChanged()

[read-only, since 6.12] status : Status

This property holds the search status

This property tells whether a search is in progress.

This property was introduced in Qt 6.12.

Access functions:

QPdfSearchModel::Status status() const

Notifier signal:

void statusChanged(QPdfSearchModel::Status status)

See also count().

Member Function Documentation

[explicit] QPdfSearchModel::QPdfSearchModel(QObject *parent)

Constructs a new search model with parent object parent.

[override virtual noexcept] QPdfSearchModel::~QPdfSearchModel()

Destroys the model.

[override virtual] QVariant QPdfSearchModel::data(const QModelIndex &index, int role) const

Reimplements: QAbstractItemModel::data(const QModelIndex &index, int role) const.

QPdfLink QPdfSearchModel::resultAtIndex(int index) const

Returns a result found by index in the document, regardless of the page on which it was found. index must be less than rowCount.

QList<QPdfLink> QPdfSearchModel::resultsOnPage(int page) const

Returns the list of all results found on the given page.

[override virtual] QHash<int, QByteArray> QPdfSearchModel::roleNames() const

Reimplements: QAbstractItemModel::roleNames() const.

[override virtual] int QPdfSearchModel::rowCount(const QModelIndex &parent) const

Reimplements: QAbstractItemModel::rowCount(const QModelIndex &parent) const.

The number of rows in the model is equal to the number of search results found.

© 2026 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.