summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-05-08 10:55:26 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-05-09 07:23:09 +0200
commit045d2259f83a20d1970ba3788361078b73b6caa5 (patch)
tree6b2602e6bfa96d2a919dd10b15b6b55c174c94b6
parentc6aa66b16364a0561ae28824ca39329ee9c4ede0 (diff)
downloadqtdeclarative-045d2259f83a20d1970ba3788361078b73b6caa5.tar.gz
Doc: make grabToImage example snippet more useful
The example doesn't work as is (when run with the qml binary) because by the time Component.onCompleted is called, there might not be a window yet. Use a key press handler instead (which then needs focus to be set). Fixes: QTBUG-113312 Change-Id: I2986334aca4ca670e206ceadf1093a87aa304e8e Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
-rw-r--r--src/quick/doc/snippets/qml/item/itemGrab.qml5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/quick/doc/snippets/qml/item/itemGrab.qml b/src/quick/doc/snippets/qml/item/itemGrab.qml
index ef4430175a..f4a5b0ba15 100644
--- a/src/quick/doc/snippets/qml/item/itemGrab.qml
+++ b/src/quick/doc/snippets/qml/item/itemGrab.qml
@@ -12,12 +12,13 @@ Rectangle {
id: sourceRectangle
width: 100
height: 100
+ focus: true
gradient: Gradient {
GradientStop { position: 0; color: "steelblue" }
GradientStop { position: 1; color: "black" }
}
- Component.onCompleted: {
+ Keys.onSpacePressed: {
sourceRectangle.grabToImage(function(result) {
result.saveToFile("something.png")
})
@@ -30,7 +31,7 @@ Image {
id: image
}
-Component.onCompleted: {
+Keys.onSpacePressed: {
sourceRectangle.grabToImage(function(result) {
image.source = result.url
}, Qt.size(50, 50))