Details
-
Task
-
Resolution: Unresolved
-
P2: Important
-
None
-
None
Description
Ideally we want to write something like:
Text { fontSize: 12pt }
How do we get there? Already today we can do the following:
- Write constructible value types called "pt" and "px" that can be constructed from a number.
- Write a value type called "screenRelatedSize" (please bikeshed the name) and make it constructible from pt or px, basically a tagged union over those, which can be resolved into some physical size if given a dpi value.
- Add a fontSize property of type screenRelatedSize to Text and have it handle whatever that produces.
Now you can write:
Text { fontSize: 12 as pt }
That's already not all that bad.
To improve on this even further, we could add a syntactical hack to the QML parser so that a number directly followed by a lowercase identifier (without space in between) is interpreted as an "as" expression. This should be possible because such a thing is currently invalid code AFAICS. With that, we can have the original form.
An argument can be had that we shouldn't actually squat such a prominent syntactical construct in case JavaScript wants to add it it itself, with different semantics. In that case we may want to either opt into this using a pragma or offer some less obvious syntax like "12_pt".
Attachments
Issue Links
- duplicates
-
QTBUG-11655 QML needs to have a resolution-independant / physical size measurement in addition to pixels
-
- Open
-