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

Add Environment concept to QML

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • Icon: Not Evaluated Not Evaluated
    • None
    • Some future release
    • None
    • 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.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            vestbo Tor Arne Vestbø
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes