I'm using Material style in my app. I know how to switch between themes using qtquickcontrols2.conf file:
[Controls]
Style=Material
[Universal]
Theme=Dark
Accent=Red
[Material]
Theme=Dark
Primary=Gray
Accent=#825AA7
But let say that I want to have predefined Material's themes like: pink, green, blue. Each one has own pedefined colors for Primary, Accent etc. User should be able to change between these themes at runtime. How to do this?
As I understand you, you want to change colors at runtime.
In your code you should add this. It uses property variables globalColor and globalTheme. (You could rename these if you want)
Material.accent: Material.color(globalColor)
Material.theme: globalTheme
property string globalColor: Material.Blue
property int globalTheme: Material.Light
If you need to change the color or theme (Dark, Light), you have to change the values of properties globalColor and globalTheme.
Also, if you need to save color and theme, you could add this piece of code in Settings (as in the example below) to save the value in the application settings.
Settings {
property string globalColor: Material.Blue
property int globalTheme: Material.Light
}
Related
I am trying to define the style of my application in the qtquickcontrols2.conf file like this:
[Controls]
Style=Material
[Material]
Theme=Light
Variant=Dense
Accent=DeepOrange
Primary=Indigo
Foreground=Blue
Background=Grey
For each of the four colors (Accent, Primary, Foreground and Background) I want to specify the shade as well. However I cannot find the syntax I should use.
Is this possible and how?
It's not currently possible. You can set it on the root object though:
ApplicationWindow {
// ...
Material.foreground: Material.color(Material.Blue, Material.ShadeA100)
}
This will propagate to every other control in the application.
Can I use the qtquickcontrols2.conf file to globally style controls such as Buttons and Labels?
For example can I do something like the following?
[Controls]
Style=Material
[Material]
Theme=Dark
[Material\Button]
Text=Red
[Material\Label]
Color=Red
The above isn't working for me. I am aware I can use the Style Singleton approach but that means I need to use the style variables in each QML document I make. It would be nicer to just change it globally something like the above if its possible.
Also: Certain configuration settings are not working. For example, the palette changes dont work but font changes do. Any idea why?
[Controls]
Style=Material
[Material]
Theme=Dark ; These changes work
Accent=Red
Palette.Base=Red ; These changes are not applied/shown?
Palette.Text=Blue
; These changes are applied/shown
[Material\Font]
Family=Open Sans
PixelSize=20
; These changes are not applied/shown?
[Material\Palette]
Base=#000000
Text=#ffffff
I have a window with Buttons, TextFields, Labels etc. These all share common properties like font family, color, size etc. What I would like to be able to do is to define a grouping of these properties (called, say, textStyles.MainTitle or textStyles.DescriptiveText etc.) that would include a font family, size and weight, height and color. And then in the QML file I would write something like:
myCustomProperty: textStyles.MainTitle
and this would apply those values to the control. How can I do this?
QML controls are styled by implementing their respective styles, for example for Button you have to implement a ButtonStyle.
As for the actual "grouping" you can just use a QtObject
property QtObject textStyles : QtObject {
property FontLoader mainTitle : FontLoader {...}
....
}
You can also extend styled components as dedicated types:
// StyledText.qml
Text {
font.family: someFont
font.pixelSize: fontSize
color: someColor
font.italic: true
font.letterSpacing: -1
...
}
And then use that by just StyledText {} instead of repeatedly styling regular Text elements.
Where / in what file do I place the QtObject snippet? I don't understand what // StyledText.qml is, or what a FontLoader is.
If you want it to be available in your entire application, you can put it as a property of your root object in main.qml, thanks to dynamic scoping textStyles will resolve from every other file in your project. You can put entire component styles in it as well and share in the project.
StyledText.qml is just an extra qml file you add to your project, you can being with just implementing its body in an existing qml file, then rightclick on Text and select refactoring -> move component into separate file.
A FontLoader is just a regular QML component, you can use it to load specific fonts and use as a font source for text. You don't have to use that, you can use font families from your system fonts as well. The font loader is useful for fonts you bundle with your application.
Simply put, I have a JavaFX Textfield that I wish to 1) change the text color on, and 2) change it back to that specified in CSS. Does anyone know how to (generally) access css colors etc. from within the JavaFX code?
AnyFxElement.setStyle(String elementCss);
For source of all the css capabilities I reccomend looking up caspian css.
To remove a style use the code:
// remove the background color on the button
yourElement.setStyle(null);
To set it back to it's default style:
// set the button style back to the default class
yourElement.setStyle(".yourStyle");
I have few questions on styles (Themes). Presently i get a blue colored theme in all my window and panels. I want to change this to Pink. How can i do that ?
I read about swapStyleSheet( String id, String url) : Void but, i am not sure how to use it.
2.) I also need to know how to change the colors of labels/form panels etc, I want all the styles to be on 1 page, rather than adding it as an attribute in labels/form panels. (eg: fieldStyle: 'background-color: #ddd; background-image: none;')
Although I have not created a custom theme, there is a themeing guide located here: http://www.sencha.com/learn/theming/ that will give you very powerful tools to create your theme instead of styling individual components.