本页内容

QQuickItemGrabResult Class

QQuickItemGrabResult 包含由QQuickItem::grabToImage() 返回的结果。更多内容...

头文件: #include <QQuickItemGrabResult>
CMake: find_package(Qt6 REQUIRED COMPONENTS Quick)
target_link_libraries(mytarget PRIVATE Qt6::Quick)
qmake: QT += quick
在 QML 中: ItemGrabResult
继承自: QObject

属性

公共函数

QImage image() const
bool saveToFile(const QString &fileName) const
(since 6.2) bool saveToFile(const QUrl &filePath) const
QUrl url() const

信号

void ready()

详细说明

另请参阅 QQuickItem::grabToImage()。

属性文档

[read-only] image : const QImage

该属性存储抓取操作得到的像素结果。

如果抓取操作尚未完成或失败,则返回一个空图像(`image.isNull() ` 将返回 `true`)。

访问函数:

QImage image() const

[read-only] url : const QUrl

该属性保存一个 URL,可与基于 URL 的图像消费者(例如 QtQuick::Image 类型)配合使用。

该 URL 在QQuickItemGrabResult 对象被删除之前一直有效。

该 URL 并不代表一个有效的文件或读取该文件的路径,它主要是一个键,用于通过Qt Quick 的基于图像的类型访问图像。

访问函数:

QUrl url() const

成员函数文档

[signal] void QQuickItemGrabResult::ready()

当抓斗操作完成时,会发出此信号。

[invokable] bool QQuickItemGrabResult::saveToFile(const QString &fileName) const

将截图结果保存为图像文件,路径为fileName 。若操作成功,则返回true ;否则返回false 。

注意:在 Qt 5.9 之前的版本中,此函数被标记为非const 。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable, since 6.2] bool QQuickItemGrabResult::saveToFile(const QUrl &filePath) const

将截图结果作为图像保存至filePath ,该路径必须指向一个扩展名为supported image format 的local file name 文件。若操作成功,则返回true ;否则返回false 。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

该函数于 Qt 6.2 中引入。

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