[Qt-qml] Fw: Why can't I stylesheet a font?
Alan Alpert
alan.alpert at nokia.com
Tue Jul 13 11:53:44 CEST 2010
On Tue, 13 Jul 2010 16:56:00 ext Jason H wrote:
> >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.
>
The paradigm here is not MVC. Maybe your attempt to use it as if it is MVC is
the problem. In MVC terms, I believe that the QML contains both the controller
and the view. I'm not denying there are trade offs to this approach, but if you
need to use strict MVC for some reason, then QML is not for you (although you
might be able to squeeze it out of QML/JS, I wouldn't recommend it).
> 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.
>
You can just go into Theme.qml. Either a ThemedText.qml following the previous
approach, or you can have a Theme.qml like below (or just put the object into
your main.qml)
Theme.qml
QtObject{
property color myFavoriteColor: 'blue'
property color mySecondColor: 'bluer'
}
main.qml
Item{
Theme{id:theme}
Text{color: theme.myFavoriteColor}
}
> 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!
>
We have anchors, which you can use already if you so choose. What feature are
you asking for? Qt's existing layout system, while great for widget UIs, does
not scale to fluidly animating UIs, so if you are asking for that you'll need
to think about how it can be implemented efficiently first.
> >> 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.
>
And with the previous approach, it would be one line in
BackgroundRectangle.qml and one line in StyledFont.qml. Because we are using
primitives, almost all text is a Text and almost all blocks of solid color are
a Rectangle.
--
Alan Alpert
Software Engineer
Nokia, Qt Development Frameworks
More information about the Qt-qml
mailing list