[Qt-qml] Fw: Why can't I stylesheet a font?

Jason H scorp1us at yahoo.com
Tue Jul 13 08:56:00 CEST 2010



>You might go so far as a file per Item per style, but that is unlikely. You 
>create the MyStyledText element, and use that for all your Text. What other 
>primitives would you style? Some, like ListViews, you'd likely want to style 
>per-instance and not in general (so you just declare those properties on that 
>ListView). What items were you planning to style this way?

All of them. Literally, all of them. Since these are just JS objects, they have 
attached properties and values, it should not matter. Just let me collect the 
properties/values into groups, and assign those groups to items. 


> When comparing QML/C++ with HTML/CSS, keep in mind that QML is the style part 
> and C++ is the data part. So it is not like HTML where you want to get all the 


> style out of the file. QML files should contain the styling, and can still use 


> components and global variables to style from the same source. This is much 
> more mixing of style and substance than in HTML/CSS, where the HTML contains 
> the building blocks of the UI and CSS styles them, but for UIs I think this is 


> a lot more appropriate and helps for a good look and feel (especially since 
>the data is still somewhere else, which I thought was the real point of CSS).

You silly trolls! Always mixing your controller with your view! (Delegates!?) 
The paradigm is MVC.  What we want is to specify the controller part apart from 
the view part. There is a little co-mingling, but HTML always defined the 
structure, CSS defined the look. Same for Qt Style sheets. The UI files 
specified the interface elements, the CSS specified the look of those elements. 
The same is true for this. 


One of the short-comings of CSS, is they weren't actually cascading. Sure, they 
"cascaded" from site to local, but what they sorely lacked was internal 
Cascading:
H1 { }
H1.bold { H1, font-weight: bold}
(Its been a while this may not compile, but you get the point)

Being able to specify an application-wide base font is huge. 
Being able to specify an application-wide color scheme is huge. 
Being able to change either with one edit to a file: priceless. Seriously, do 
you know how much editing it would take?

I can't count the number of times when someone said: 
"Make it blue-er"
"Make it bigger"

Would you really have me go through all the files and add 1 or 2 to every 
font.pointSize or pixelSize? Or would you rather go into theme.qml and change 
one setting - the base font size? Would you rather me repeat that for colors? 
QML is supposed to be about sexy interfaces - Developers and Arts working 
together. 


I have a complete disdain for hardcoding anything in a UI. (Blame yourselves and 

your awesome layout managers.) Everytime I see something hard coded, I shudder. 
This might not be a problem for whole screen apps, on pixel limited devices 
(phones, tablets) but this is huge problem on the desktop. (I still don't know 
how to react to the viewer resize... (my preference is scale everything)). The 
only thing that should ever be hard-coded is the initial Rectangle which defines 

the viewport, and the base font size. Everything else should be dynamically 
resolved through anchors. 


You're so close to Nirvana... just add this feature! 

>> And the fact that I can specify font and color (which isn't a part of
>> font!?) at the same time is really handy.

>Perhaps I didn't understand what you meant here, but why can't you do that 
>with the separate file?

You said: "This means that you only use the properties relevant for that  type." 

Which is true. I can't specify font color, with the font. (Which is a whole 
other can of worms, because in HTML, <font color="... and in CSS, font-color: 
...) Meaning that I can't use the proposed approach optimally because I have to 
specify color everywhere.

Consider this: I change my color scheme from bluetext/evergreen background to 
black text/bright green background. How many places should I need to change? 
Two. The font color and the background color. Without this I'd have to hunt for 
every mention of "White" and all its other variations (RGB FFFFFF). Nokia seems 
to recognize this with the color.lighter()/darker() mechanism which provides 
relative colors. 


If you go to market without this in QML 1.0, the world won't implode but we'll 
be forced into maintianing many more thousands of lines of QML which are all 
basically duplicates of the same thing. 






> ----- Original Message ----
> From: Alan Alpert <alan.alpert at nokia.com>
> To: qt-qml at trolltech.com
> Sent: Tue, July 13, 2010 12:30:37 AM
> Subject: Re: [Qt-qml] Why can't I stylesheet a font?
> 
> On Tue, 13 Jul 2010 10:48:46 ext Gregory Schlomoff wrote:
> > I second that. Would be very useful to be able to create a predefined
> > group of properties, and then assign the group as a whole to any
> > object.
> > 
> > Something like this:
> > 
> > PropertyGroup {
> > 
> >   id:bigText
> >   font.face = "Arial"
> >   font.pointSize: 30
> >   color: "red"
> > 
> > }
> > 
> > Text {
> > 
> >   text:"Hello"
> >   properties: [bigText, anotherSetOfProperties]
> > 
> > }
> 
> Something also like that, but that you can do in QML today, is:
> 
> MyText.qml
> Text{
>     font.face: "Arial"
>     font.pointSize: 20
>     color: "red"
> }
> main.qml
> 
> MyText{
>     text: "Hello"
> }
> 
> This approach has the advantage of being linked to the type. This means
> that you only use the properties relevant for that type. Also the
> precedence is clear, so if you want to set a different color but keep the
> other properties, that's easy and should be unambiguous.
> 
> The downside of this approach is that you need an extra file, but
> presumably if these properties are worthwhile separating out you may want
> to use them in multiple files anyways.

-- 
Alan Alpert
Software Engineer
Nokia, Qt Development Frameworks


      




More information about the Qt-qml mailing list