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

ShaderEffectSource clears window of sourceItem

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12
    • None
    • MacBook Pro
      macOS 10.13.6
    • macOS

    Description

      In the following example, clicking the "Pick up" button should unparent sceneItem from scene and it should be instead shown by ShaderEffectSource in the GridView. When "Drop" is clicked, sceneItem should be parented back to scene and shown in its original position.

      What actually happens is that sceneItem is never shown because it has no window.

      To reproduce it, run the following example, click "Pick up", then "Drop".

      sceneItem loses its window when the delegate is removed from the view, just because the ShaderEffectSource references sceneItem. The order of events is:

      • sceneItem unparented
      • View model count gets set to zero, QQuickItemViewPrivate::clear() is called
      • QQuickItemViewPrivate::releaseItem(FxViewItem *) is called
      • QQuickItem::setParentItem(QQuickItem *) is called
      • QQuickItemPrivate::derefWindow() is called, and it calls itself for each child item
      • QQuickShaderEffectSource::itemChange() gets called and calls QQuickItemPrivate::get(m_sourceItem)->derefWindow();

      I think the last part is the bug. I already explicitly parented sceneItem to the scene, so it shouldn't undo that.

      The example is deliberately contrived in order to demonstrate the issue with the minimal amount of code. In the real use case, there is a proper C++ model, etc.

      The reason for wanting to use ShaderEffectSource here is that sceneItem may be displayed in several places, so it's not possible to just e.g. reparent it to the delegate, as that would still leave other places where it wouldn't be able to be shown.

      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.0
      import QtQuick 2.0
      import QtQuick.Window 2.0
      
      ApplicationWindow {
          id: window
          width: 320
          height: 480
          visible: true
      
          header: RowLayout {
              Button {
                  text: "Pick up"
                  onClicked: sceneItem.parent = null
              }
              Button {
                  text: "Drop"
                  onClicked: sceneItem.parent = scene
              }
          }
      
          Rectangle {
              id: sceneItem
              objectName: "sceneItem"
              color: "steelblue"
              width: 32
              height: 32
          }
      
          GridView {
              anchors.fill: parent
              anchors.margins: 50
              model: !sceneItem.parent ? 1 : 0
              delegate: ItemDelegate {
                  width: 32
                  height: 32
      
                  ShaderEffectSource {
                      smooth: false
                      sourceItem: sceneItem
                      width: 32
                      height: 32
                      anchors.centerIn: parent
                  }
              }
      
              Rectangle {
                  anchors.fill: parent
                  color: "transparent"
                  border.color: "darkorange"
              }
          }
      
          Item {
              id: scene
              anchors.fill: parent
          }
      }
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-70814
          # Subject Branch Project Status CR V

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              mitch_curtis Mitch Curtis
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change