Qt is an awesome framework for building responsive desktop applications. Before releasing an application though, you will need to deal with issues involving DPI. Depending on your target OS there are a few options and issues to consider. Qt gives some helpful information here.
On Windows you need to understand that there are 3 levels of dpi-awareness your application can have. By default a Qt application declares itself dpi-aware, either per-screen-awareness for Windows 8.1+, or system-wide-awareness for older Windows versions. This means that you will need to do some work to make your application adjust appropriately.
The Easy Way
If you are targeting Windows only, then there is an easy solution to make a dpi-unaware application look good on all displays. Simply tell windows that your application is dpi-unaware and Windows will scale the application window so it looks normal on high-dpi displays that have fonts scaled.
Just add a qt.conf file to your application directory that contains the following:
[Platforms]
WindowsArguments = dpiawareness=0
The Right Way (AFAIK)
To make your application actually be dpi-aware you will need to keep track of the logical dpi of the screen that your window is displayed on. Use QScreen::logicalDotsPerInch() to obtain this value. Create a scaling factor to be used in your application by dividing this value by a standard constant dpi, typically 96. Use the scaling factor in your UI to scale images and geometry as needed. You will not need to scale fonts if they are set in point size because Qt will scale them automatically. Alternatively, you can set your font size in pixels and multiply the size by the scaling factor. In testing I found this to work best.
You will also need to keep track of the screen your application window is on. This can be done by connecting a handler to the QWindow::screenChanged() signal. When the screen changes, update the scaling factor appropriately. You should also connect a handler to the QScreen::logicalDotsPerInchChanged() signal to detect when the dpi changes.
Conclusion
Hopefully these tips will help you create a more dpi-friendly application. Here is an example project I created that shows how to do some of this. Enjoy!
Comments
Post a Comment