Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Destroying an Item that was set as the sourceItem for a ShaderEffectSource hides the ShaderEffectSource as well
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 307 Views 1 Watching
  • 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 Monov76S Offline
    Stefan Monov76S Offline
    Stefan Monov76
    wrote on last edited by
    #1

    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
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved