Skip to content

Theme/Sizing/Layout control based on attached object #19213

@micieslak

Description

@micieslak

Description

Currently the global singleton Theme is used to control colors, paddings and related features.

This approach gives one global point of control, affecting always the entire app. It also introduces mutable global state because we need ability to modify style on the fly.

This approach is limiting when it comes to isolation and testing. Changing theme-related properties has always global impact. The ability to fine tune component for a particular context without affecting other places is not possible or at lest not easy and elegant.

The proposed alternative approach assumes using mechanism of attached properties, especially dynamically propagated attached properties (https://doc.qt.io/qt-6/qquickattachedpropertypropagator.html).

Than vast majority of fixed values may still remain in global singleton, as a read only values. But all mutable properties could go to attached properties, providing more fine-grained control. It includes paddings, font sizes, palettes for light/dark theme and potentially other values that we want to alter on the fly or have different in different parts of the application.

This approach would allow implementing sizing policies per container depending on it's size, rather then single global-one that's not possible to be altered in a straightforward way. It also means that the same component can be used with different sizing in different places of the application. It's not possible where all size-related values come from global singleton.

Sample usage:

UserListPanel {

   Theme.padding: width < 400 ? ThemeConstants.padding / 2 : ThemeConstants.padding 
}

It'd also possible to use Binding to bind value conditionally and keep value inherited from the parent otherwise.

This approach, in opposition to global factor, allows more fine-grained customization. This seems to be beneficial as it's almost impossible to find global coefficient working well in cases.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions