Well I've applied some singleton style in my QML components and with those variable settings I cannot see the proper QML designer view. It's clear that Qt Designer is not able to read those variable values from my style file and render properly.
Is there any way to view the component in designer mode when using style variables? In below snippet if I pass actual values designer shows the component as expected.
What is best practice in QML to apply common component coloring and sizing factors?
WaveComponent.qml
Rectangle {
id: waveRect
width: Style.waveBlockWidth
height: Style.waveBlockHeight
color: Style.blockColor
radius: Style.blockRadius
}
Related
I have a program that can load plugin modules and these plugin modules I don't have much control over (outside of instructing customers about guidelines on how to create their modules).
I'm, however, trying to create some Style Themes (e.g. 'lightTheme' and 'darkTheme') for my application that I'd also like to propagate to any UI elements that may be created in any plugins.
Here's my problem, in one of the plugins I noticed that a bare QWidget (e.g. QWidget *widget = new QWidget(); was created that has no parent and I'm trying to figure out how to style this window.
Qt in this case treats this view kind of like a QDialog, however in the stylesheet I need to use QWidget to style this view (QDialog doesn't do anything). As you might expect adding style to QWidget (e.g. QWidget { background-color: black; } with cause a whole host of other style changes throughout my program that I don't want.
So what I'm looking for is how to "style a QWidget that doesn't have a parent".
I was expecting to do something like:
parent > QWidget { background-color: black; }
But I can't figure out what to put for the 'parent' since I know this widget has no parent.
Any help would be appreciated.
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.
Is it possible to apply CSS styles to a dialogue or wizard modal window in Eclipse? I've been able to use the CSS Spy plug-in to figure out most elements but when I bring a modal up, Spy becomes inactive.
Yes it is possible for dialogs and wizards that you create. However changing some of the styles of a dialog or wizard can be quite tricky (such as the dialog background). To some extent you can also apply styles to existing dialogs.
For dialogs you create you probably want to set a CSS class for the dialog area to make it easier to specify styles applying just to the dialog:
#Override
protected Control createDialogArea(final Composite parent)
{
Composite composite = new Composite(parent, SWT.NONE);
composite.setBackgroundMode(SWT.INHERIT_DEFAULT);
WidgetElement.setCSSClass(composite, "DialogClass");
...
This sets the CSS class and the composite background mode.
You can also apply styles to any dialog using CSS selectors in the form:
Shell[style~='SWT.APPLICATION_MODAL'] > Composite > Text
{
font-size: 14pt;
}
which applies the style to a Text control in a application model dialog.
An example Dialog with styling:
No. The CSS styling feature works on Eclipse 4 workbench model which represents the workbench window along with editors and views within it, but not the content of editors, views or dialogs.
I know that QML does not support CSS styling like widgets do, and I have read up on alternative approaches to styling/theming:
https://qt-project.org/wiki/QmlStyling
http://www.slideshare.net/BurkhardStubert/practical-qml-key-navigation/34
Common for these approaches is that they require the developer to specify the parts of the QML that can be styled, either by binding to a property in a “styling QML file/singleton”, or by using a Loader to load a different QML component based on style name. What I would like is something that works like the "id" selector in CSS instead of the "class" selector, so that the individual QML files do not have to know whether they will be styled later on or not.
My current approach make all the QML files look similar to this (using approach in link 2):
Main.qml
Rectangle {
Id: background
color: g_theme.background.color
//g_theme is defined in root context and loaded dynamically
}
What I would like to do is:
Main.qml
Rectangle {
Id: background
color: “green” // default color
}
And then have a styling file that defines (or similar)
Main.qml #background.color: red
Is this possible at the moment, or something that is in the pipeline for a future Qt version, or will the preferred way of styling continue to be something similar to the approach described in the links above?
The preferred way isn't applying a style on default components, but deriving from these components to create pre-styled custom components.
What I do for my projects :
First, I create one centralized 'theme' file, as a JavaScript shared module :
// MyTheme.js
.pragma library;
var bgColor = "steelblue";
var fgColor = "darkred";
var lineSize = 2;
var roundness = 6;
Next, I create custom components that rely on it :
// MyRoundedRect.qml
import QtQuick 2.0;
import "MyTheme.js" as Theme;
Rectangle {
color: Theme.bgColor;
border {
width: Theme.lineSize;
color: Theme.fgColor;
}
radius: Theme.roundness;
}
Then, I can use my pre-styled component everywhere with a single line of code :
MyRoundedRect { }
And this method has a huge advantage : it's really object-oriented, not simple skinning.
If you want you can even add nested objects in your custom component, like text, image, shadow, etc... or even some UI logic, like color-change on mouse hover.
PS : yeah one can use QML singleton instead of JS module, but it requires extra qmldir file and is supported only from Qt 5.2, which can be limiting. And obviously, a C++ QObject inside a context property would also work (e.g. if you want to load skin properties from a file on the disk...).
It could also be helpful to look at Qt Quick Controls Styles
When using Controls Styles it is not necessary to explicitly assign each property in the target control. All properties can be defined in a separate [ControlName]Style component (e.g. ButtonStyle).
Then in target component (e.g. Button) you can just reference to style component in one line of code.
The only one downside here is that Style components are available for Qt Quick Controls only. Not for any Qt Component.
For example the spark ComboBox.
Where is the default skin?
Is it generated (at compile or runtime)?
If it was in fact written by someone how does the compiler/Virtual Machine know where to find the skin class? I didn't see a location specified in the ComboBox source.
Thanks!
Edit: Sorry originally meant to say skin by typed style instead
Spark components use mostly skins. The default skin is defined in the defaults.css file which gets compiled into the spark.swc. The CSS for ComboBox looks like this:
ComboBox
{
/* dropShadowVisible: true; in spark.css */
paddingBottom: 3;
paddingLeft: 3;
paddingRight: 3;
paddingTop: 5;
skinClass: ClassReference("spark.skins.spark.ComboBoxSkin");
}
So, the class spark.skins.spark.ComboBoxSkin is defined as default skin for ComboBox. You can find the complete file in your Flex SDK (frameworks/projects/spark/defaults.css).
If you want to find out more about this take a look at the following topics on Adobe Flex Help:
About Spark
skins
Applying styles from a defaults.css file