Skip to content

Commit

Permalink
Doc: improve grabToImage snippets
Browse files Browse the repository at this point in the history
- Change the code that is quoted so that the indenting looks sane
- Make it possible to copy and run the first snippet without
  modification
- Make it easier to copy and run the second snippet without
  modification
- Move itemGrab.qml to item sub-directory
- Generally tidy up

Pick-to: 6.2 6.4 6.5
Change-Id: I608b7a6025b9866c14b84420ae64827965a7519f
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
  • Loading branch information
mitchcurtis committed Dec 14, 2022
1 parent 6de2397 commit f0f9bac
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 57 deletions.
39 changes: 39 additions & 0 deletions src/quick/doc/snippets/qml/item/itemGrab.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2014 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick 2.4

Item {
width: 320
height: 480

//! [grab-to-file]
Rectangle {
id: sourceRectangle
width: 100
height: 100
gradient: Gradient {
GradientStop { position: 0; color: "steelblue" }
GradientStop { position: 1; color: "black" }
}

Component.onCompleted: {
sourceRectangle.grabToImage(function(result) {
result.saveToFile("something.png")
})
}
}
//! [grab-to-file]

//! [grab-to-image]
Image {
id: image
}

Component.onCompleted: {
sourceRectangle.grabToImage(function(result) {
image.source = result.url
}, Qt.size(50, 50))
}
//! [grab-to-image]
}
50 changes: 0 additions & 50 deletions src/quick/doc/snippets/qml/itemGrab.qml

This file was deleted.

12 changes: 5 additions & 7 deletions src/quick/items/qquickitemgrabresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,15 @@ QSharedPointer<QQuickItemGrabResult> QQuickItem::grabToImage(const QSize &target
*
* If the grab could not be initiated, the function returns \c false.
*
* The following snippet shows how to grab an item and store the results to
* a file.
* The following snippet shows how to grab an item and store the results in
* a file:
*
* \snippet qml/itemGrab.qml grab-source
* \snippet qml/itemGrab.qml grab-to-file
* \snippet qml/item/itemGrab.qml grab-to-file
*
* The following snippet shows how to grab an item and use the results in
* another image element.
* another image element:
*
* \snippet qml/itemGrab.qml grab-image-target
* \snippet qml/itemGrab.qml grab-to-cache
* \snippet qml/item/itemGrab.qml grab-to-image
*
* \note This function will render the item to an offscreen surface and
* copy that surface from the GPU's memory into the CPU's memory, which can
Expand Down

0 comments on commit f0f9bac

Please sign in to comment.