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

Consider allowing initialisation of many themes

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Quick: Controls 2
    • Labels:
      None
    • Technical Risk:
      Normal

      Description

      In 5.15, importing QtQuick.Controls will result in the theme for the current style being loaded:

      https://code.qt.io/cgit/qt/qtquickcontrols2.git/tree/src/imports/controls/qtquickcontrols2plugin.cpp?h=5.15#n263

      It loaded the plugin(s) specified by the qmldir of the current style, and then called initializeTheme(theme) on it:

      https://code.qt.io/cgit/qt/qtquickcontrols2.git/tree/src/imports/controls/qtquickcontrols2plugin.cpp?h=5.15#n120

      The documentation says:

      The fallback style must be the name of one of the built-in Qt Quick Controls styles, e.g. "Material".

      If the user sets "MyStyle" as the style, and "Material" as the fallback, no QQuickTheme will be initialised at all, since QQuickStylePlugin and QQuickTheme are not public, so the user has no official(ly documented) way of implementing them. Users can still affect how the controls they implement look, just not via QQuickTheme. The Material style will still be used for the controls that the user's custom style doesn't implement, and because of QQuickMaterialStyle::initGlobals(), those controls will have the correct colours, but anything set by QQuickMaterialTheme will not be used.

      When we introduce a public API for styling, QQuickTheme and QQuickStylePlugin will be available to users and so they can implement their own themes that will be used. However, I see two issues:

      1. If we want the Material and Universal styles to make use of the palette API (like Default, Fusion and Imagine do), they'll need to stop using their attached API for colours. This will render initGlobals() useless, and so then both fonts and colours from those themes will not take effect.
      2. Fonts from fallback themes will still not be used. I don't know if this was intentional or not: maybe the idea was that the current style gets to choose the font and that it should apply to every control scope.

      There are potentially three styles used in one application: the current style, the fallback style, and the Default style, which is used as an implicit/final fallback if another style is set as the fallback.
      I'm wondering if we can initialise all three themes, starting backwards:

      • QQuickDefaultTheme::initialize() is called
      • QQuickMaterialTheme::initialize() is called
      • MyStyleTheme::initialize() is called

      That way, each theme can set its fonts and colours, and the current theme always wins if more than one theme sets a font or palette for a given scope.

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              mitch_curtis Mitch Curtis
              Reporter:
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes