Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-64945

Item.grabToImage() does not work on ApplicationWindow items

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.12.0 RC
    • 5.9.3
    • Quick: Controls 2
    • None
    • Qt 5.9.3, Windows 7, mingw 5.3.0.

    Description

      I want do take a screenshot of my application. I want all visible objects in the screenshot.

      I've tried to use grabToImage on ApplicationWindow.overlay. It gives an error :

      <Unknown File>: QML QQuickOverlay: grabToImage: item has no QML engine

       I've tried ApplicationWindow.contentItem instead, to be sure to have an Item, it gives an error :

      <Unknown File>: QML QQuickItem: grabToImage: item has no QML engine

      If I copy overlay with a ShaderEffectSource, and grabs the result, it works.

       

      Here is a small code in order to reproduce the problem :

      import QtQuick 2.7
      import QtQuick.Controls 2.2
      import QtQuick.Layouts 1.3
      import QtQuick.Window 2.0
      import QtMultimedia 5.8
      import Qt.labs.settings 1.0
      import QtGraphicalEffects 1.0
      
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
          id:root
      
      
          property alias theContentItemContent: theContentItemContent
          Rectangle
          {
              id: theContentItemContent
              color: "red"
              width: 100
              height: width
              anchors.centerIn: parent
              MouseArea
              {
                  anchors.fill: parent
      //            onClicked: root./*theContentItemContent*/overlay.grabToImage(function(img) {console.log("grab callback called"); rawIHMImage.source = img.url; work(); }, Qt.size(500, 500) )
                  // <Unknown File>: QML QQuickOverlay: grabToImage: item has no QML engine
      //            onClicked: root./*theContentItemContent*/contentItem.grabToImage(function(img) {console.log("grab callback called"); rawIHMImage.source = img.url; work(); }, Qt.size(500, 500) )
                  //<Unknown File>: QML QQuickItem: grabToImage: item has no QML engine
                  onClicked: root.theContentItemContent.grabToImage(function(img) {console.log("grab callback called"); rawIHMImage.source = img.url; work(); }, Qt.size(500, 500) )
              }
          }
      
      
          Image
          {
              parent: overlay
              id: rawIHMImage
              anchors.horizontalCenter:   theContentItemContent.horizontalCenter
              anchors.top: theContentItemContent.bottom
              visible: true
              onSourceChanged: console.log(source)
              width: 150
              height: width
              y:200
              z:1500
              Text {
                  id: name
                  text: qsTr("text")
              }
          }
      
      
          function work() { console.log("work called"); rawIHMImage.width *= .95; rawIHMImage2.visible = false; shaderCopy.grabToImage(function(img) {console.log("grab callback 2 called"); rawIHMImage2.source = img.url; rawIHMImage2.visible = true; } )}
      
      
          Image
          {
              parent: overlay
              id: rawIHMImage2
              x:100
              visible: true
              onSourceChanged: console.log(source)
              width: 300
              height: width
              z:1501
          }
      
      
          ShaderEffectSource {
              id: shaderCopy
              visible: false
              sourceItem: root.overlay
              anchors.fill: parent
              Rectangle
              {
                  color: "blue"
                  width: parent.width
                  height: 50
              }
              Rectangle
              {
                  color: "green"
                  width: parent.width
                  height: 50
                  anchors.bottom: parent.bottom
              }
          }
      }
      
      

       

      Attachments

        1. qml-screenshot.zip
          2 kB
          Artem Sidyakin
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            sr__ sr__
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes