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

ListView.section update context properties instead of required properties

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 6.7.1, 6.7.2
    • Quick: Other
    • None
    • All

      If ListView is used as root in a custom component that requires additional properties this goes wrong.

      The culprit is the following code for method getSectionItem in qquicklistview.cpp 

      if (delegatePriv->hadTopLevelRequiredProperties()) {
          delegate->setInitialProperties(nobj, {{QLatin1String("section"), section}});
      } else if (!reuseExistingContext) {
          context->setContextProperty(QLatin1String("section"), section);
      }

      This means that if required properties are used they are initialized. The context is not used.
      Later when the section is updated with `setSectionHelper` we have a context and the lookup for the 'section' property always succeeds as the ListView is a parent that has a section property.
      So the context property is updated but the required property of the delegate is left alone.

       

      The following patch is needed:

      const bool isBound = delegate->isBound();
      auto delegatePriv = QQmlComponentPrivate::get(delegate);
      const bool useRequiredProperties = delegatePriv->hadTopLevelRequiredProperties();
      const bool reuseExistingContext = isBound || useRequiredProperties;

       

      That way no context is initialized when the required properties are used anyways.
      You can use useRequiredProperties in the conditions as well.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            arbmind Andreas Reischuck
            Votes:
            8 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes