Bug 420439 - item.grabToImage() does not work in a KQuickAddons::ConfigModule
Summary: item.grabToImage() does not work in a KQuickAddons::ConfigModule
Status: RESOLVED UPSTREAM
Alias: None
Product: frameworks-kdeclarative
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Marco Martin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-22 23:27 UTC by Janet Blackquill
Modified: 2020-04-23 06:56 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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