[Interest] specifying units in Qt style sheets

Hamish Moffatt hamish at risingsoftware.com
Fri Jun 21 07:06:23 CEST 2013


Hi,

I'm trying to make my app work for a variety of screen sizes and 
densities, I'm using style sheets as much as possibly to control the 
size of things. Since I want things to be the same physical size across 
devices generally, I'm trying to specify things in points (which are 
1/72 inches by definition, and converted to pixels with reference to the 
pixel density of the device).

The style sheet reference implies that any "Length" type value can be 
specified in pt, px, em or ex. But I'm not clear on the exact syntax. 
I've tried the following;

font-size: 50pt; -- works
font-size: 50 pt; -- does not work - results in default font size
font-size: 50px; -- works
font-size: 50 px; -- does not work - results in default font size

margin-left: 100pt; -- does not work - results in 0 px
margin-left: 100 pt; -- does not work - results in 100 px regardless of 
pixel density
margin-left: 100 px; -- works
margin-left: 100px; -- works

A quick glance at the source code (for both 4.8.4 and 5.0.1) shows

- there's a length parser for fonts, which only understands "pt" and 
"px", not "em" and "ex";
- there's another parser for other lengths, which understands "px", "em" 
and "ex" but not "pt". Hence my points being treated like px above.

It's not really clear what font the "em" and "ex" are being calculated 
against in that case.

I think these are bugs. But either way I think my attempt to work in 
points is doomed as a result.

Any other suggestions how I can achieve this?



Thanks

Hamish



More information about the Interest mailing list