QPdfSearchModel Class

QPdfSearchModel 类可在 PDF 文档中搜索字符串并保存搜索结果。更多

Header: #include <QPdfSearchModel>
Inherits: QAbstractListModel

公共类型

enum class Role { Page, IndexOnPage, Location, ContextBefore, ContextAfter }

属性

公共函数

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

重新实现的公共函数

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

公共插槽

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

信号

详细说明

模型/视图编程范式中,该函数用于显示搜索结果列表,在渲染的 PDF 页面上高亮显示这些结果,并使用 "向前搜索"/"向后搜索 "按钮和快捷方式遍历这些结果,这些在典型的文档查看用户界面中都能找到:

成员类型文档

enum class QPdfSearchModel::Role

常数说明
QPdfSearchModel::Role::PageQt::UserRole搜索结果所在页面的页码(int)。
QPdfSearchModel::Role::IndexOnPage257搜索结果在页面上的索引(int)。
QPdfSearchModel::Role::Location258搜索结果在页面上的位置 (QPointF)。
QPdfSearchModel::Role::ContextBefore259页面上搜索字符串之前的相邻文本 (QString)。
QPdfSearchModel::Role::ContextAfter260页面上搜索字符串之后的相邻文本 (QString)。

另请参阅 QPdfLink

属性文档

[read-only, since 6.8] count : const int

该属性保存搜索结果的数量

此属性在 Qt 6.8 中引入。

访问函数:

int count() const

Notifier 信号:

void countChanged()

document : QPdfDocument*

该属性包含要搜索的文件

访问功能:

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

通知信号:

void documentChanged()

searchString : QString

该属性包含要搜索的字符串

访问功能:

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

Notifier 信号:

void searchStringChanged()

成员函数文档

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

构建一个新的搜索模型,其父对象为parent

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

破坏模型。

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

重实现:QAbstractItemModel::data(const QModelIndex &index, int role) const.

QPdfLink QPdfSearchModel::resultAtIndex(int index) const

index document index 必须小于 。rowCount

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

返回在给定page 上找到的所有结果列表。

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

重实现:QAbstractItemModel::roleNames() const.

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

重实现:QAbstractItemModel::rowCount(const QModelIndex &parent) const。

模型中的行数等于找到的搜索结果数。

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