QML switch themes based on one on runtime - qt

I'd like to have a control switching light and dark themes in my Qt project on runtime.
I need both themes to be based on Material style.
According to the documentation, I know that I can modify my style properties in qtquickcontrols2.conf file what could lead to sth like this:
[Controls]
Style=Material
[Material]
Accent=#2331aa
Primary=#926ec4
Variant=Dense
Foreground=#233232
Background=#F5F1FD
But what if I need to have both Material.Light and Material.Dark styles customized and switchable?
Could someone provide a minimalist working example of how to do that?

Related

Material UI Homepage Theme?

I have attached an image of the demo that is displayed on the main page for Material UI. I really like this theme and I want to use one like it with MUI to create my web application. Is there any way that I can use this theme (style my components like this) or do I have to replicate it from scratch?
You can find the code for that theme here: https://github.com/mui/material-ui/blob/v5.8.0/docs/src/modules/brandingTheme.ts.
You can see it used here: https://github.com/mui/material-ui/blob/v5.8.0/docs/src/BrandingProvider.tsx#L23.
I've created a code sandbox that demonstrates using this theme: https://codesandbox.io/s/mui-docs-theme-example-0mys5d?file=/index.tsx. brandingTheme.ts in the sandbox is an exact copy of the file in GitHub. It is then used from within index.tsx in the sandbox. demo.tsx just shows a few different components in order to see the theme in action.
If you want to implement your own fancy theme, you can simply customize the MUI theme using theming or even modify components' style like this!.
Take a look at premium template if you want to buy something.
There are also a few free themes you may find just but googling like:
Free React Dashboard...

Add CSS component to Qt QML

I am new to QML, so I wanted to ask .. is it possible to import/convert/use CSS templates in QT ?
because I found many stylish CSS component. more than QML templates.
QML by default allows CSS styling with limited options. The limitations are mentioned here.
But if your intention is to add a .css file into the project and make that as a style sheet then there is no default way.
Here is the out of the box project with GitHub, which allows direct integration of CSS style sheets into QML. You can refer to the examples in that project

Can I use Qt Creator's new Flat theme in my application?

The new Flat theme of QtCreator looks nice and I want to apply to my application.
I know how to use QApplication::setStyle() to set a theme, but I don't know if this new theme ships with Qt at all, and if it ships, what is its name.
I searched for the flat theme file in my Qt install, and I found it at c:\Qt\Tools\QtCreator\share\qtcreator\themes\flat.creatortheme.
The flat theming was added by
commit Implement theming for QtCreator.
Here's the commit message:
Implement theming for QtCreator
Adds a 'Theme' tab to the environment settings and a '-theme' command
line option.
A theme is a combination of colors, gradients, flags and style
information.
There are two themes:
- 'default': preserves the current default look
- 'dark': uses a more flat for many widgets, dark color theme
for everything
This does not use a stylesheet (too limited), but rather sets
the palette via C++ and modifies drawing behavior.
Overall, the look is more flat (removed some gradients and bevels).
Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE
Desktop (Oxygen base style).
For a screenshot, see
https://gist.github.com/thorbenk/5ab06bea726de0aa7473
Changes:
- Introduce class Theme, defining the interface how to access theme
specific settings. The class reads a .creatortheme file (INI file, via
QSettings)
- Define named colors in the [Palette] section
(see dark.creatortheme for example usage)
- Use either named colors of AARRGGBB (hex) in the [Colors]
section
- A file ending with .creatortheme may be supplied
to the '-theme' command line option
- A global Theme instance can be accessed via creatorTheme()
- Query colors, gradients, icons and flags from the theme
were possible (TODO: use this in more places...)
- There are very many color roles. It seems better to me
to describe the role clearly, and then to consolidate later
in the actual theme by assigning the same color.
For example, one can set the text color of the output pane button
individualy.
- Many elements are also drawn differently.
For the dark theme, I wanted to have a flatter look.
- Introduce Theme::WidgetStyle enum, for now {Original, Flat}.
- The theme specifies which kind of widget style it wants.
- The drawing code queries the theme's style flag and
switches between the original, gradient based look and
the new, flat look.
- Create some custom icons which look better on dark background
(wip, currently folder/file icons)
- Let ManhattanStyle draw some elements for non-panelwidgets, too
(open/close arrows in QTreeView, custom folder/file icons)
- For the welcomescreen, pass the WelcomeTheme class.
WelcomeTheme exposes theme colors as Q_PROPERTY accessible from
.qml
- Themes can be modified via the 'Themes' tab in the environment
settings.
TODO:
* Unify image handling
* Avoid style name references
* Fix gradients
Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944
Reviewed-by: Thomas Hartmann
Reviewed-by: hjk
I have no experience with QML, but maybe the file is all you need, I don't know.
Check in src/libs/utils/theme/theme.cpp. It will probably be some work to extract that and generalize it for other applications.

codename one using gui builder and css.

I am building a cn1 app and was so far using the "Theme" in the GUI Builder to change the look of containers and buttons. I now want to add a specific border to a container and I find it easier to accomplish the border through css, I found the instructions on how to do it and the code here: https://www.codenameone.com/blog/rounded-corners-shadows-and-gradients-with-css.html . I added the .jar, made a css folder and add my theme.css file with the code. In my form's beforeshow method I change the uiid of a container to the uiid defined in my theme.css. However when I run the app the container takes on the default Container uiid, not the one defined in my .css. I feel like this is because I already have a theme defined in my gui builder with my uiids and now I am trying to change a container's uiid to a uiid defined in another theme. Is there something I'm doing wrong here?
If I understand correctly you have two themes and you want to use elements from both in the app. There are two valid scenarios, one where both of the themes are in the same res file and another where both of the themes are in a separate file.
If they are in the same res file do this:
theme = UIManager.initNamedTheme("/theme", "firstTheme");
UIManager.getInstance().addThemeProps(theme.getTheme("secondTheme"));
If they are in a separate files do this:
theme = UIManager.initNamedTheme("/theme", "firstTheme");
Resources otherTheme = Resources.openLayered(("/otherTheme");
UIManager.getInstance().addThemeProps(otherTheme.getTheme("secondTheme"));
This is discussed in the Codename One Developer Guide under Theme Layering.

Flex change color values in skin with something like ResourceManager

I'm working on a project that requires us to be able to define a color scheme via a properties file post compile.
Currently we have a skin swc that defines our custom skins and have moved the color values to an actionscript file. This works well for centralizing the skin colors but doesn't allow us to change the values without recompiling.
I was thinking to use the ResoureManager for this task but we also have to support localization. As far as I know you can only specify one locale so we can't hack the ResourceManager for our purposes.
Anyone have an idea of how this can be accomplished?
Thanks in advance!
Put your color scheme in a style sheet and load it at runtime.
So when you change you stylesheet, you odon't recompile your application, only the style sheet.
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f8c.html

Resources