[Qt-qml] Fw: Why can't I stylesheet a font?
Jason H
scorp1us at yahoo.com
Wed Jul 14 04:58:02 CEST 2010
"we often have things like color: focus ? "green" : "red"; how would that
work?"
color: focus ? prefs.focusInColor : prefs.focusOutColor
where prefs is a object like:
PropertyGroup {
id: prefs
property string focusInColor: "green"
property string focusOutColor: "red"
}
I'll probably adopt Alan's Approach #2.
----- Original Message ----
From: "michael.brasser at nokia.com" <michael.brasser at nokia.com>
To: scorp1us at yahoo.com
Cc: qt-qml at trolltech.com
Sent: Tue, July 13, 2010 10:39:24 PM
Subject: Re: [Qt-qml] Fw: Why can't I stylesheet a font?
On 14/07/2010, at 10:42 AM, ext Jason H wrote:
> But the ability to define and apply arbitrary property groups - be they be for
> themes or something else - has a good bit of support and application. Can we
>get
>
> the feature? Please?
>From my perspective, the main requirement is "make it easy for designers to
change the visual aspects of a large QML project". The below approaches help to
achieve that, and are available for use right now. For future releases (the
feature set of 4.7 is essentially frozen), we should certainly look at how well
this approach has served, and how we can better meet this goal. Something like
PropertyGroups should be part of the research (we'll need to answer questions
like how it fits in with states, or bindings (we often have things like color:
focus ? "green" : "red"; how would that work?), what the performance
implications are, and how much improvement it gives us for the costs). If you'd
like to help, trying the techniques below in your project for a couple months,
and providing feedback on what worked and what didn't as opposed to another
system like CSS that you are familiar with, would be invaluable.
Current Approach 1
------------------
If you've got a single, unique set of properties to apply, Alan's first
suggestion of custom components works really well.
//BigText.qml
Text {
font.family: "Arial"
font.pointSize: 30
color: "red"
}
//everywhere else
BigText { test: "Hello" }
In my mind, this is essentially identical (at least in expressiveness) to:
Text {
text:"Hello"
properties: [bigText]
}
(i.e. when one PropertyGroup is applied.) One difference is that the BigText
approach would lead to a directory full of these small files, while the
PropertyGroup approach would lead to a file full of small snippets. In both
cases the potential navigation problems (lots of files or really large file)
should be solvable by good tooling.
Current Approach 2
------------------
Alan's second suggestion regarded a master theme file:
//the theme definition
QtObject {
id: bigText
property string family: "Arial"
property real pointSize: 30
property color color: "red"
}
QtObject {
id: anotherSetOfProperties
property color color: "purple"
}
//everywhere else
Text {
text: "Hello"
font.family: bigText.family
font.pointSize: bigText.fontSize
color: bigText.color
styleColor: anotherSetOfProperties.color
}
Like the PropertyGroup approach below, this allows applying global properties
that are defined in a single file.
Text {
text:"Hello"
properties: [bigText, anotherSetOfProperties]
}
Unlike the PropertyGroup approach, it is "fixed" what properties from what
groups apply. This has both pros (e.g. less possibility of unintended
side-effects) and cons (e.g. more work when adding a new property to a "style").
It also requires more typing initially.
Hybrid Approach
---------------
You can also combine approach 1 and 2, e.g.
//BigText.qml
Text {
font.family: bigText.family
font.pointSize: bigText.fontSize
color: bigText.color
styleColor: anotherSetOfProperties.color
}
Regards,
Michael
More information about the Qt-qml
mailing list