[Development] New approach to hi-dpi and coordinate system for layouts in Qt 6

Stephen Kelly stkelly at microsoft.com
Fri Sep 22 13:56:06 CEST 2017


Hi Jean-Michaël,

The issue is layouting, not painting. Sorry for not making that clear.

Feel free to modify the example code I posted if you think you have a general solution with QPen::setCosmetic alone to fix the layout issues.

Thanks,

Stephen.

From: doom.ooseventh at gmail.com [mailto:doom.ooseventh at gmail.com] On Behalf Of Jean-Michaël Celerier
Sent: Thursday 21 September 2017 11:29
To: Stephen Kelly <stkelly at microsoft.com>
Cc: development at qt-project.org
Subject: Re: [Development] New approach to hi-dpi and coordinate system for layouts in Qt 6

> making it impossible to specify 'a one/two pixel border'
Correct me if I am wrong, but isn't this what QPen::setCosmetic is used for ?
Best,
Jean-Michaël



-------
Jean-Michaël Celerier
http://www.jcelerier.name<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jcelerier.name&data=02%7C01%7Cstkelly%40microsoft.com%7Ca935be0873684c352c8508d500dba175%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636415865659940051&sdata=1lMb5KQYE4VI5h4ZWvpQI42CRFLYXIQD648n0r5esEY%3D&reserved=0>

On Thu, Sep 21, 2017 at 11:37 AM, Stephen Kelly via Development <development at qt-project.org<mailto:development at qt-project.org>> wrote:

Hi,

Qt 5 has several approaches to attempting to size/scale a UI when moving between screens which have
different APIs.  There is a summary here:

https://vicrucann.github.io/tutorials/osg-qt-high-dpi/<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fvicrucann.github.io%2Ftutorials%2Fosg-qt-high-dpi%2F&data=02%7C01%7Cstkelly%40microsoft.com%7Ca935be0873684c352c8508d500dba175%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636415865659940051&sdata=VYg7fbhhcBr3f69cSTiFRV8TxXCUMJ%2BuJsiGOF5WyGE%3D&reserved=0>

The approaches available currently either

1) scale everything after rendering (eg with SetProcessDPIAware())
2) scale coordinates to screen metrics before rendering (QApplication::setAttribute(Qt::AA_EnableHighDpiScaling))

The first approach gives a blurry result because of up/down scaling and is not satisfying.

The second approach scales all coordinates, making it impossible to specify 'a one/two pixel border' without that getting scaled too. Additionally, the AA_EnableHighDpiScaling will only apply integer scaling, so on a screen with 150% scaling, the widget is scaled to 200%.

Adding a floating-point based API would not be a solution because it would result in painting artefacts.  This is an important point.  An approach like that won't satisfy designers.  The approach in

https://codereview.qt-project.org/#/c/157174/<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcodereview.qt-project.org%2F%23%2Fc%2F157174%2F&data=02%7C01%7Cstkelly%40microsoft.com%7Ca935be0873684c352c8508d500dba175%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636415865659940051&sdata=9bK3ZwKx91cmG3qJIcNToe5ajsUYq0P5JNmUuBai%2Fys%3D&reserved=0>

resolves a scaling issue but does not address painting artefacts.

So, we need to find flexible and imaginative solutions.

I've had a discussion on IRC with Morten, who worked on QUIP-8.  That QUIP doesn't (yet?) go as far as approaches to addressing the problem, so I am writing here to see if there is wider interest in the topic.  One of the points he made is that some users are happy with the current state of Qt APIs and behavior, or would be happy with downsampling after rendering (blurry).

I don't know how widespread that acceptance would be, but I've worked on several teams where it would not be acceptable.

The underlying problem is that the Qt APIs do not provide a way to specify the units to use in layouts AND to combine values with those units.  We need to be able to specify coordinates which will be scaled to an appropriate number of pixels on the screen, but also to be able to specify coordinates in exact pixels (common for things like having a 'one/two pixel border' etc).  Then, Qt should compute the actual number of pixels to paint based on the current screen.

The approach we discussed (this is only the ideas-stage, remember!) with Morten is to change APIs which specify layouts to use a new unit-sensitive coordinate type instead of int.  This new QCoordinate type stores values in both points and pixels and has a toPixels method which computes the required pixel value for the screen.

https://gist.github.com/anonymous/d08e0e79b05237a765e23849bbe2a78d<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgist.github.com%2Fanonymous%2Fd08e0e79b05237a765e23849bbe2a78d&data=02%7C01%7Cstkelly%40microsoft.com%7Ca935be0873684c352c8508d500dba175%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636415865659940051&sdata=3lAJTdxL0UIj6366wsWIAwKb9cRxNpTLh26xNXc02hs%3D&reserved=0>

QCoordinates can be created with C++11 user-defined literal niftyness:

  auto coord = 34_pt + 4_px;

This also implies a requirement to have QSize/QPoint etc equivalents based on QCoordinate.  We haven't put much thought into this code duplicatation etc, focusing only on whether we can solve the problems with this approach (or another approach?) at all.

A disadvantage of the QCoordinate approach is that the values are not comparable to each other without a screen.  So operator<() can't be implemented for example, but a separate purposeful API would be needed for things like that.

One of the issues raised so far is that this QCoordinate stores only pixels and points, but not other units which may be wanted, such as physical units like centimeters.  Morten noted that there are not many known use-cases for such units and that they mean little if a projector is in use.

This is of course a Qt 6 change, and now is approximately the time to discuss Qt 6 changes.  I don't know if anyone will be in Berlin who wants to discuss this at QtCS.  Shout if you want to discuss this there and I'll see if I can go over for it.

Thanks,

Stephen.


_______________________________________________
Development mailing list
Development at qt-project.org<mailto:Development at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/development<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.qt-project.org%2Fmailman%2Flistinfo%2Fdevelopment&data=02%7C01%7Cstkelly%40microsoft.com%7Ca935be0873684c352c8508d500dba175%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636415865659940051&sdata=fPXUZEbKnNV1ibN1OeILyFkTwnP3YFxmr8K0IdHBCRQ%3D&reserved=0>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20170922/0f443818/attachment.html>


More information about the Development mailing list