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

Add Environment concept to QML

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • Some future release
    • None
    • All

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              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

              Dates

                Created:
                Updated: