QPdfPageNavigator Class

PDF 文档中的导航历史记录。更多

Header: #include <QPdfPageNavigator>
Since: Qt 6.4
Inherits: QObject

属性

公共功能

QPdfPageNavigator(QObject *parent)
virtual ~QPdfPageNavigator() override
bool backAvailable() const
QPointF currentLocation() const
int currentPage() const
qreal currentZoom() const
bool forwardAvailable() const

公共插槽

void back()
void clear()
void forward()
void jump(QPdfLink destination)
void jump(int page, const QPointF &location, qreal zoom = 0)
void update(int page, const QPointF &location, qreal zoom)

信号

void backAvailableChanged(bool available)
void currentLocationChanged(QPointF location)
void currentPageChanged(int page)
void currentZoomChanged(qreal zoom)
void forwardAvailableChanged(bool available)
void jumped(QPdfLink current)

详细说明

QPdfPageNavigator 类会记住用户在 PDF 文档中访问过的目的地,并提供向前和向后浏览的功能。该类用于实现类似于网页浏览器中前进和后退按钮的前进和后退操作。

另请参阅 QPdfDocument

属性文档

[read-only] backAvailable : const bool

如果历史记录中存在返回目标,即调用了 push() 或forward() 后,则保留true

访问功能:

bool backAvailable() const

通知信号:

void backAvailableChanged(bool available)

[read-only] currentLocation : const QPointF

此属性保存正在查看的页面上的当前位置(最后给jump() 或update() 的位置)。默认值为0, 0

访问功能:

QPointF currentLocation() const

Notifier 信号:

void currentLocationChanged(QPointF location)

[read-only] currentPage : const int

该属性包含当前正在浏览的页面。默认值为0

访问功能:

int currentPage() const

通知信号:

void currentPageChanged(int page)

[read-only] currentZoom : const qreal

该属性用于保存正在查看的页面的放大比例(1 逻辑像素 = 1 点)。默认值为1

访问功能:

qreal currentZoom() const

通知信号:

void currentZoomChanged(qreal zoom)

[read-only] forwardAvailable : const bool

如果历史记录中存在转发目的地,即back() 之前已被调用,则保留true

访问功能:

bool forwardAvailable() const

Notifier 信号:

void forwardAvailableChanged(bool available)

成员函数 文档

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

通过父对象parent 构建页面导航栈。

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

销毁页面导航堆栈。

[slot] void QPdfPageNavigator::back()

弹出堆栈,将currentPagecurrentLocationcurrentZoom 属性更新为最近查看的目标,然后发出jumped() 信号。

[slot] void QPdfPageNavigator::clear()

清除历史记录,并将currentPagecurrentLocationcurrentZoom 恢复为默认值。

[slot] void QPdfPageNavigator::forward()

返回到调用back() 之前正在浏览的页面、位置和缩放级别,然后发出jumped() 信号。

如果在上次调用back() 之后又推送了新的目的地,forward() 函数将不起任何作用,因为时间轴上的分支会导致 "未来 "丢失。

[slot] void QPdfPageNavigator::jump(QPdfLink destination)

将给定的destination 添加到历史访问位置中。

在这种情况下,PDF 视图对jumped 信号的响应是通过滚动将destination.rectangles 放在视口中,而不是将destination.location 放在视口中。因此,调用此方法从QPdfSearchModel 跳转到搜索结果是合适的(因为矩形覆盖了找到的文本区域)。如果要跳转到超链接的目的地,则应调用 jump(page,location,zoom),因为在这种情况下,QPdfLink 对象的rectangles 会覆盖超链接的起始位置,而不是目的地。

[slot] void QPdfPageNavigator::jump(int page, const QPointF &location, qreal zoom = 0)

将给定的目的地(由pagelocationzoom 组成)添加到已访问位置的历史记录中。

zoom 参数表示放大倍数(其中1 为默认比例,1 逻辑像素 = 1 点)。如果zoom 未给出或为0currentZoom 将保留其现有值,而currentZoomChanged 将不会发出。

如果用户跟踪的是链接,location 应与QPdfLink::location() 相同;由于指定的是目的地的左上角,为了保持一致,最好始终使用视口左上角可见的位置(以点为单位)。

如果forwardAvailabletrue ,调用此函数表示时间轴上的一个分支,会导致 "未来 "丢失,因此forwardAvailable 将变为false

[signal] void QPdfPageNavigator::jumped(QPdfLink current)

当发生突然跳转时,current 页面索引、页面上的位置和缩放级别都会发出这个信号;但如果只是一页一页地滚动浏览文档,则不会发出这个信号。也就是说,jump() 、forward() 和back() 会发出这个信号,但update() 不会。

如果是current.rectangles.length > 0 ,它们是覆盖特定目标区域的矩形:应使其可见的搜索结果;否则,current.locationpage 上的目标位置(超链接目标,或在向前/向后导航过程中)。

[slot] void QPdfPageNavigator::update(int page, const QPointF &location, qreal zoom)

修改当前目的地,包括pagelocationzoom

当用户在文档中手动移动时,可以定期调用此功能,这样在调用back() 后,forward() 将跳回最近查看的目标地址,而不是上次由 push() 指定的目标地址。

如果实际更改了相应的属性,则会发出currentZoomChangedcurrentPageChangedcurrentLocationChanged 信号。jumped 信号不会发出,因为该操作代表的是平滑移动,而不是导航跳转。

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