Bug 420439

Summary: item.grabToImage() does not work in a KQuickAddons::ConfigModule
Product: [Frameworks and Libraries] frameworks-kdeclarative Reporter: Janet Blackquill <uhhadd>
Component: generalAssignee: Marco Martin <notmart>
Status: RESOLVED UPSTREAM    
Severity: normal CC: kde, kdelibs-bugs, nate
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:

Description Janet Blackquill 2020-04-22 23:27:54 UTC
Expected behaviour: item.grabToImage() works as expected.
Actual behaviour: "QML <ItemType>: grabToImage: item's window is not visible"

Example: 

---
import QtQuick 2.6
import org.kde.kcm 1.2 as KCM

KCM.ScrollViewKCM {
  Rectangle {
    id: rect
    width: 50
    height: 50
    color: "red"
    MouseArea {
      anchors.fill: parent
      onClicked: {
        rect.grabToImage(function(result) {})
        // QML Rectangle: grabToImage: item's window is not visible
      }
    }
  }
}
---
Comment 1 Kai Uwe Broulik 2020-04-23 06:34:20 UTC
Looks like a Qt bug. We use QQuickWidget to embed QtQuick into a widget window which uses an offscreen window. 

    if (!item->window()->isVisible()) {
        qmlWarning(item) << "grabToImage: item's window is not visible";
        return nullptr;
    }

I wonder if using QQuickRenderControl::renderWindowFor(item->window()) instad of item->window() directly here would work