Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Destroying an Item that was set as the sourceItem for a ShaderEffectSource hides the ShaderEffectSource as well

    QML and Qt Quick
    1
    1
    227
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Stefan Monov76
      Stefan Monov76 last edited by

      What I'm doing, in short:

      • I have a ShaderEffectSource Item named snapshotItem with live: false
      • Dynamically instantiating an Item called dynamicItem
      • Setting snapshotItem.sourceItem = dynamicItem
      • Calling snapshotItem.scheduleUpdate()
      • At this point, I successfully see two copies of dynamicItem on screen
      • On any key, I:
      • set snapshotItem.sourceItem to an empty, dummy Item, to make the next step less likely to cause problems
      • destroy dynamicItem

      The problem is that when a key is pressed, both copies disappear from screen, when I want the snapshotItem one to remain.

      Note: If you're interested in the motivation behind wanting to achieve this, see my previous question.

      My code:

      import QtQuick 2.6
      import QtQuick.Window 2.2
      
      Window {
          visible: true
          width: 640
          height: 480
          
          property int childWidth: 100
          property int childHeight: 100
          
          id: root
          property var dynamicItem
          
          Item {
              id: dummy
          }
          
          Component {
              id: dynamicItemComponent
              Rectangle {
                  color: "red"
              }
          }
          
          Component.onCompleted: {
              dynamicItem = dynamicItemComponent.createObject(row);
              dynamicItem.width = childWidth;
              dynamicItem.height = childHeight;
              snapshotItem.sourceItem = dynamicItem;
              snapshotItem.scheduleUpdate();
          }
          
          Item {
              focus: true
              Keys.onPressed: {
                  snapshotItem.sourceItem = dummy;
                  dynamicItem.destroy();
              }
          }
          
          Row {
              id: row
              spacing: 10
              ShaderEffectSource {
                  id: snapshotItem
                  live: false
                  width: childWidth
                  height: childHeight
              }
          }
      }
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post