-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
Consider this test case:
TestCase { id: testCase visible: true Rectangle { id: redRectangle color: Qt.rgba(1, 0, 0, 255) height: 100 width: 100 } // the greenRectangle is in front of the redRectangle Rectangle { id: greenRectangle color: Qt.rgba(0, 1, 0, 255) height: 100 width: 100 } function test_saveImage() { waitForRendering(redRectangle, 1000); let image = grabImage(redRectangle); // this test fails because the returned color is GREEN // this is because it is the window that is grabbed, not the item - the item is only used for its geometry to trim the image. // See the actual code here: https://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/qmltest/quicktestresult.cpp#n758 compare(image.pixel(0, 0), Qt.rgba(1, 0, 0, 1)); } }
All is explained in comments. Since green rectangle comes later in order so it is stacked on top of red one. So what actually gets grabbed by "grabImage" is a green pixel.
By "grabImage", user expects the item to be grabbed. That is what documentatiob suggests:
"Returns a snapshot image object of the given item".
But no, it is the section of containing Window that intersects with the item. Item itself is not directly grabbed. Z order matters.