[Development] High-dpi Qt best practices
Rutledge Shawn
Shawn.Rutledge at digia.com
Wed Oct 10 17:31:04 CEST 2012
On 10 Oct 2012, at 4:56 PM, Olivier Goffart wrote:
> What is wrong with this alternative:
>
> All the API stays always in pixel (QIcon, QWidget::geometry, ...)
>
> QCoreApplication::setAttribute(Qt::AA_MacHighDPI)
> (should it maybe be even be set by default?)
>
> If that is set, everything is in pixel, but the default font size is twice as
> big, the mac style returns pixelmetrics ans sizes that are twice as big, and
> all the widgets are then automatically twice as big
>
> In general, that's the way to do it. Having hardcoded pixel value has always
> been a bad practice with Qt.
> Application that did it will possibly look bad on high-res display and will
> need to be fixed. But I think they will need the same amount of fixes with
> the other appreach because sometimes they really mean pixel, sometimes they
> mean point.
I agree that in retrospect, using pixels as units was a bad idea. This is why we need to provide a way to design UI's in millimeters IMO. But it cannot be done in time for Qt 5. If that was possible, then maybe in the distant future pixels could go back to being real physical pixels again.
But I don't think I have a problem with the idea of "logical pixels" being the short-term direct replacement as a unit of measurement, but I think we should consistently call them logical pixels rather than "points" (because points are really physical units, like mm). Overriding the DPI is simply the existing way of adjusting the screen resolution on Linux and Windows. Certainly if you run X11 on a high-DPI display you will want to set the DPI to something like 96 to avoid getting tiny unreadable legacy apps. It's too bad you can't directly control the DPI on MacOS in a similar way, but that's Apple's shortcoming. They might be expected to fix it if there is a proliferation of different display resolutions in the future.
I don't worry about layout issues so much, because anyone who knows how to properly use the layout managers in Qt has never has a problem with that; it's a very powerful feature which is necessary to have cross-platform apps. If the app writer didn't use layouts properly, he or she can fix that. And it will deal with unexpectedly large fonts just fine. Nevertheless, Designer still puts some pixel sizes into UI files, such as the initial size of the outer widget or window. So for consistency it seems we need to treat those as logical pixel units rather than physical pixels, otherwise apps might start up with default window sizes which are not sufficient to hold the contents, and then people will come up with dodgy workarounds like sizing the window in proportion to screen size, starting up maximized by default, and so on.
> The only thing is about QPen. should we draw lines twice as large? that is
> bascically what QPen::isCosmetic is for.
It seems to me that to be consistent, for non-cosmetic pens it should multiply the width by the ratio of physical DPI / logical DPI. Except that probably a zero-width line should be always one physical pixel wide (the point of specifying zero is to mean "make it as fine as possible while still being visible"). Because there must be some context in which a really fine line is actually what you want.
More information about the Development
mailing list