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

As a developer, I want to have public read-only access to explicitVisible/explicitEnabled members of QQuickItem

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • None

    Description

      Motivation:
      Visible and Enabled properties of QQuickItem are special properties and when we read it, we get from QQuickItem not the same what we set to it.

      See: https://doc.qt.io/qt-6/qml-qtquick-item.html#visible-prop

      They can be impacted by any its parents state or by internal Qt scene recalculation. And it triggers corresponding visibleChanged, enabledChanged signals -> all bindings to these properties will be triggered even if real conditions set in particular Item to that properties were not changed.

      In some cases it leads to unnecessary calls / recalculations and can impact performance.

      In these cases it is not expected to call these bound slots if original condition was not changed.

       

      // Simplified case
      Item {
         id: a
         Item {
            id: b
            Item {
               id: c
               visible: true
               onVisibleChanged: {
                   console.log("c.visible = " + visible)
               }
            }
         }
      }
      
      function foo() { 
          b.visible = !b.visible // => "c.visible = false"
      }
      
      function bar() {
          a.visible = !a.visible // => "c.visible = false"
      }
       
      function action() {
         trackedConnection.target = c;
      }
      
      function someExternalAction() {
         a.visible = !a.visible;
      }
      
      Connection {
          id: trackedConnection
          target: someItem
          function onVisibleChanged(){
              requestDataAndRecalculateContent();
          }
      }

       

      QQuickItem has private members which keep values of these original conditions: explicitVisible/explicitEnabled . However, QQuickItem does not provide public (at least read-only) access to them.

      To have an access to that functionality developers have to add dependency to private Qt headers to the project. Which is not a good practice.

      Or do other workarounds like re-implementing setVisible() method and introduce own copy of the same explictVisible/Enabled members in derived component. However, it works unexpectedly when the component is operable later by other logic as pointer to QQuickItem - setVisible() is not a virtual method and setting of that own explicit members are not called when logic calls it like QQuickItem *widget = ...;  widget->setVisible(..).

      Request:

      please provide public access to explicitVisble / explicitEnabled properties of QQuickItem

      To have public read-only access to explicitVisible / explicitEnabled properties/members of QQuickItem can make development more convenient, easier, reliable and avoid unnecessary dependencies on Qt private headers.

      Possible solutions:

      • provide just public c++ get methods and changed signals (minimal solution)
      • provide corresponding QML read-only properties (preferable solution, allows to have safe bindings to original condition on QML side)

      Attachments

        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
            mjnikoff Ivan Maiornykov
            Votes:
            8 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes