[Development] Scalable UIs in QtQuick (take 2)

André Somers andre at familiesomers.nl
Thu Feb 18 14:07:03 CET 2016



Op 18/02/2016 om 11:50 schreef Hausmann Simon:
> Hi,
>
> A little while ago Lars and I proposed to introduce physical units in the QML language for use in QtQuick. The idea was to make it easier to write user interfaces that adapt to different display resolutions by "pinning" your UI to physical dimensions. For example you could say
>
>      Image {
>          source: "mypprofilephoto.png"
>          width: 5cm
>          height: 5cm
>      }
>
> and the image size in physical pixels would scale accordingly to always produce a 5cmx5cm profile image on the screen. The proposed units included "px", which was really an alias for nothing.
>
> We've had some very good discussions around this at last year's contributor summit as well as in smaller face-to-face discussions. The main feedback I recall was that this would seem like a nice feature on paper but in practice people create their resolution independent interfaces using the current "pixels" and a scale factor that they introduce in a qml file or as a context property. That's another way of saying that perhaps the feature wouldn't really find any use, which is fair :). Instead the desire was expressed that making it _easier_ to scale "logical" pixels in the application would perhaps be better.
>
> So today during a discussion another idea came up:
>
> (1) In order to make it really easy to scale "logical" pixels without having to introduce your own context property or factor in a .qml file that you multiply everywhere, we could turn the regular "pixels" in QtQuick into truly logical pixels that scale with an application wide (or window wide) factor. So Image { width: 100 ... } will scale automatically from 100 logical pixels to maybe 200 physical pixels on a x2 display. This assumes the availability of API to change this mapping.
>
> (2) In the events where you still _want_ to use physical pixels, you could use "px" units.
>
> So at first nothing would change for app developers at all because we map logical pixels to physical pixels. But
> if you'd like to, you could opt into changing this mapping and having a relatively easy fallback to physical pixels using for example the "px" unit. We might as well offer the other physical units anyway, that probably causes little to no harm.
>
> What do you think?
>
I'd like to have something like that. I would be wonderful to be able to 
specify units, even if you do that through some scaling factor.
Please also take font sizes into account though. Sizes specified in 
points are supposed to be a physical size I'd think (it is defined as 
1/72th of an inch). I'd really like it if those actually come out in the 
right size.

I am thinking about an unusual case: print templates. I have been (and 
still am) working on a print engine that uses QML for its print 
templates. In such templates, physical size is much more relevant than 
pixel size. After all, every printer has a different resolution, but you 
want your printout to look the same anyway.

André



More information about the Development mailing list