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

Add Environment concept to QML

XMLWordPrintable

    • All

      It would be nice if QML had a dedicated type for specifying "environments" that are inherited by child items:

      App.qml

      Item {
        Environment.theme: MyTheme{}
      
        ColumnLayout {
          StyledButton {}
          StyledButton {}
        }
      }
      

      StyledButton.qml

      Item {
        Rectangle { color: Environment.theme.buttonBackgroundColor }
        ...
      }
      

      This is similar to what QQuickAttachedObject allows, but without having to use private api (QTBUG-63267) and without having to use C++.

      Swift has a similar feature: https://developer.apple.com/documentation/swiftui/environment

      A workaround for this today is context properties, but they have many downsides.

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

            qtqmlteam Qt Qml Team User
            vestbo Tor Arne Vestbø
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes